Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a Process with an Impersonated User
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01059576
Message ID:
01059585
Views:
14
Hi Anatoliy, thanks for replying!

In order to test the code you supplied me, could you please clarify some issues:

1) In the code fragment below:
 cStartInfo = num2dword (68)                   + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (STARTF_USESHOWWINDOW) + ;  &&  <<<-------
              num2dword (SW_SHOWNORMAL)        + ;  &&  <<<-------
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)                    + ;
              num2dword (0)

 nCreationFlags = NORMAL_PRIORITY_CLASS     + ;
                  CREATE_DEFAULT_ERROR_MODE + ;  &&  <<<-------
                  CREATE_NEW_CONSOLE        + ;  &&  <<<-------
                  CREATE_NEW_PROCESS_GROUP       &&  <<<-------
Where can I obtain the code for num2dword () procedure?

would it be like:
 Function Long2Str
*-------- --------
 LParameters pLongVal

 Private I, cRetStr, nLongVal

 cRetStr  = ""
 nLongVal = pLongVal

 For I = 24 To 0 Step -8

     cRetStr  = Chr (Int (nLongVal / (2^I))) + cRetStr
     nLongVal = Mod (     nLongVal,  (2^I))

 EndFor

 Return cRetStr

 EndFunc 
Where can I find the values (#Define) for STARTF_USESHOWWINDOW, SW_SHOWNORMAL, CREATE_DEFAULT_ERROR_MODE, CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP ?

2) In the CreateProcessAsUser api call:
 IF CreateProcessAsUser (nToken              , ;  &&  <<<-------
                         cApp                , ;  &&  <<<-------
                         " " + ALLTRIM (cCmd), ;  &&  <<<-------
                         0                   , ;
                         0                   , ;
                         0                   , ;
                         nCreationFlags      , ;
                         0                   , ;
                         cDir                , ;
                         @cStartInfo         , ;
                         @cProcInfo          ) = 0
Is variable 'nToken' the value returned by:
 nSuccess = LogonUser (cLoginId                 , ;
                       cDomain                  , ;
                       cPassword                , ;
                       LOGON32_LOGON_INTERACTIVE, ;
                       LOGON32_PROVIDER_DEFAULT , ;
                       @nToken                  )    &&  <<<-------
Is variable 'cApp' = Chr (0) in this case?

Is variable 'cCmd' the task to be executed (i.e. 'C:\Temp\Test.bat, for instance)

Thanks for your help and patience :)

Regards,

Fernando


>Fernando,
>
>This is the way I call this function and it seems working:
>* ... skipped...
>	DECLARE INTEGER CreateProcessAsUser IN advapi32;
>		INTEGER hToken, STRING lpApplicationName, STRING lpCommandLine,;
>		INTEGER lpProcessAttributes, INTEGER lpThreadAttributes,;
>		INTEGER bInheritHandles, INTEGER dwCreationFlags,;
>		INTEGER lpEnvironment, STRING lpCurrentDirectory,;
>		STRING @lpStartupInfo, STRING @lpProcessInformation
>* ... skipped...
>	cProcInfo = REPLICATE(CHR(0), 16)
>	cStartInfo = num2dword(68) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(STARTF_USESHOWWINDOW) +;
>		num2dword(SW_SHOWNORMAL) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0) +;
>		num2dword(0)
>
>	nCreationFlags = NORMAL_PRIORITY_CLASS + CREATE_DEFAULT_ERROR_MODE +;
>		CREATE_NEW_CONSOLE+CREATE_NEW_PROCESS_GROUP
>
>	IF CreateProcessAsUser(nToken, cApp, " " + ALLTRIM(cCmd),;
>		0,0,0, nCreationFlags,0, cDir, @cStartInfo, @cProcInfo) = 0
>		* 1314 = ERROR_PRIVILEGE_NOT_HELD
>		? "Error:", GetLastError()
>		= CloseHandle(nToken)
>		RETURN .F.
>	ENDIF
>* ... skipped...
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform