1. Menna Pablo Javier
  2. PowerBuilder
  3. Monday, 1 August 2022 19:29 PM UTC

Hi,

I would like to know if this is possible to do with PowerBuilder.

From a client-server application, I have to save files to a file repository, with a specific windows user (with administrator permissions), which is not the user currently logged in.

I thank you in advance for the help.

Regards

Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 2 August 2022 13:00 PM UTC
  2. PowerBuilder
  3. # 1

 

First add these external functions:

Function boolean LogonUser ( string lpszUsername, string lpszDomain,
         string lpszPassword, ulong dwLogonType, ulong dwLogonProvider,
         Ref long phToken ) Library "advapi32.dll" Alias For "LogonUserW"

Function boolean ImpersonateLoggedOnUser ( long hToken ) Library "advapi32.dll"

Function boolean RevertToSelf ( ) Library "advapi32.dll"

The following function can be used to impersonate any user that you know the password of. When done, call RevertToSelf.

public function boolean impersonate (string as_domain, string as_username, string as_password);// -----------------------------------------------------------------------------
// SCRIPT:     Impersonate
//
// PURPOSE:    This function allows you to change the security context to any valid user.
//
//					To release the user security, call RevertToSelf.
//
// ARGUMENTS:  as_domain	- Domain Name (for local use single period)
//					as_username	- The username to connect as
//					as_password	- The password for the user
//
// RETURN:		True=Success, False=Failed
//
// DATE        PROG/ID		DESCRIPTION OF CHANGE / REASON
// ----------  --------		-----------------------------------------------------
// 08/14/2020	RolandS		Initial coding
// -----------------------------------------------------------------------------

Constant ULong LOGON32_LOGON_BATCH = 4
Constant ULong LOGON32_PROVIDER_DEFAULT = 0
Boolean lb_Result
Long ll_Token

lb_Result = LogonUser(	as_username, &
			as_domain, &
			as_password, &
			LOGON32_LOGON_BATCH, &
			LOGON32_PROVIDER_DEFAULT, &
			ll_Token )
If Not lb_Result Then Return False

lb_Result = ImpersonateLoggedOnUser(ll_Token)
If Not lb_Result Then Return False

Return True

end function

 

Comment
  1. Steen Jakobsen
  2. Thursday, 4 August 2022 13:20 PM UTC
Great example. Thanks Roland.
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 2 August 2022 05:45 AM UTC
  2. PowerBuilder
  3. # 2

I don't kinow a way how to do it directly from Powerbuilder.

But what probably could work:

Save the file first to a directory the user have permissons for (e.g. TEMP dir).

Then use psexec tool (from sysinternals) to run the move command to move the file to the repoository. You can run it from PowerBuilder.

Psexec allows to specify the credentials the move command should run with.

 

Comment
There are no comments made yet.
Steen Jakobsen Accepted Answer Pending Moderation
  1. Tuesday, 2 August 2022 05:33 AM UTC
  2. PowerBuilder
  3. # 3

I would like to know that also.

Anyone ?

 

//Steen

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.