Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating a Process with an Impersonated User
Message
De
22/10/2005 09:56:28
 
 
À
19/10/2005 10:31:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Divers
Thread ID:
01059576
Message ID:
01061388
Vues:
20
Hi Herman,

Thanks for the hint, I was missing that point.

Regards,

Fernando

>Hi Fernando,
>
>FYI, CreateProcessWithLogonW is UNICODE. So, you have to convert the all string parameters into UNICODE, including the null terminator. If you need to interact (UI) with the called application, you must have access to Interactive Windows Desktop and Station.
>
>I haven't try this (I'm at WinME right now), but take a look at MSKB #285879. This VB article show the use (and the rule) of CreateProcessAsUser and CreateProcessWithLogonW.
>
>Good luck!
>
>
>>Thanks, Sergey! (making some testing now with RUNAS, as you pointed to me...)
>>
>>BTW, also tried CreateProcessAsUser(), but due to security issues am now trying CreateProcessWithLogonW () (please see below)., but so far am getting error #2 (system could not locate the spacified file).
>>Regards,
>>
>>Fernando
>>
>> Clear DLLs
>>
>>* Logon Flags
>>
>> #Define LOGON_WITH_PROFILE          0x00000001
>> #Define LOGON_NETCREDENTIALS_ONLY   0x00000002
>>
>>* Creation Flags
>>
>> #Define CREATE_SUSPENDED            0x00000004
>> #Define CREATE_NEW_CONSOLE          0x00000010
>> #Define CREATE_NEW_PROCESS_GROUP    0x00000200
>> #Define CREATE_UNICODE_ENVIRONMENT  0x00000400
>> #Define CREATE_SEPARATE_WOW_VDM     0x00000800
>> #Define CREATE_DEFAULT_ERROR_MODE   0x04000000
>>
>>* Priority Flags
>>
>> #Define NORMAL_PRIORITY_CLASS         32
>> #Define IDLE_PRIORITY_CLASS           64
>> #Define HIGH_PRIORITY_CLASS          128
>> #Define REALTIME_PRIORITY_CLASS     1600
>>
>> #Define STARTF_USESHOWWINDOW        1
>> #Define SW_SHOWNORMAL               1
>>
>> Declare Integer CreateProcessWithLogonW In advapi32 String   lpUsername          , ;
>>                                                     String   lpDomain            , ;
>>                                                     String   lpPassword          , ;
>>                                                     Integer  dwLogonFlags        , ;
>>                                                     String   lpApplicationName   , ;
>>                                                     String   lpCommandLine       , ;
>>                                                     Integer  dwCreationFlags     , ;
>>                                                     Integer  lpEnvironment       , ;
>>                                                     String   lpCurrentDirectory  , ;
>>                                                     String  @lpStartupInfo       , ;
>>                                                     String  @lpProcessInformation
>>
>>
>> cUsername            = "MyUsername"
>> cPassword            = "MyPassword"
>> cDomain              = "MyDomain"
>> nLogonFlags          = LOGON_NETCREDENTIALS_ONLY
>> cApplicationName     = "c:\windows\notepad.exe" + chr (0)
>> cCommandLine         = chr (0)
>>
>> nCreationFlags       = NORMAL_PRIORITY_CLASS     + ;
>>                        CREATE_DEFAULT_ERROR_MODE + ;
>>                        CREATE_NEW_CONSOLE        + ;
>>                        CREATE_NEW_PROCESS_GROUP
>>
>> nEnvironment         = 0
>> cCurrentDirectory    = chr (0)
>>
>> cStartupInfo         = 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)
>>
>> cProcessInformation  = Replicate (Chr (0), 16)
>>
>> If CreateProcessWithLogonW ( cUsername          , ;
>>                              cDomain            , ;
>>                              cPassword          , ;
>>                              nLogonFlags        , ;
>>                              cApplicationName   , ;
>>                              cCommandLine       , ;
>>                              nCreationFlags     , ;
>>                              nEnvironment       , ;
>>                              cCurrentDirectory  , ;
>>                             @cStartupInfo       , ;
>>                             @cProcessInformation) = 0
>>
>> 	ShowLastError ()
>>
>>	Return
>>
>> EndIf
>>
>>
>>* ===========================================================================
>>
>> Procedure ShowLastError
>>*-------- --------------
>>
>> #Define FORMAT_MESSAGE_FROM_SYSTEM 4096
>>
>> Declare Integer GetLastError  In Kernel32
>>
>> Declare Integer FormatMessage In Kernel32 Integer dwFlags        , ;
>>                                           String  lpSource       , ;
>>                                           Integer dwMessageId    , ;
>>                                           Integer dwLanguageId   , ;
>>                                           String  @lpBuffer      , ;
>>                                           Integer nSize          , ;
>>                                           Integer Arguments
>>
>> nLastError   = GetLastError  ()
>> cMessageText = Space         (256)
>> nRetCode     = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, nLastError, 0, @cMessageText, 256, 0)
>>
>> Messagebox ("Error #" + lTrim (Str (nLastError)) + ":" + cMessageText)
>>
>> Return
>>
>>* ===========================================================================
>>
>> Function num2dword (lnValue)
>>*-------- ---------
>>
>> #DEFINE m0  0x0000100
>> #DEFINE m1  0x0010000
>> #DEFINE m2  0x1000000
>>
>> IF lnValue < 0
>>    nValue = 0x100000000 + lnValue
>> ENDIF
>>
>> LOCAL b0, b1, b2, b3
>>
>> b3 = Int(lnValue/m2)
>> b2 = Int((lnValue - b3*m2)/m1)
>> b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
>> b0 = Mod(lnValue, m0)
>>
>> RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
>>
>> EndFunc
>>
>>* ===========================================================================
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform