FourLC Posted January 19, 2008 Share Posted January 19, 2008 Hello,This little code don't work...why ?CODEopt("RunErrorsFatal",0)opt("MustDeclareVars",0);For 'CreateProcessWithLogonW' -> dwLogonFlagsGlobal Const $LOGON_WITH_PROFILE = 0x1Global Const $LOGON_NETCREDENTIALS_ONLY = 0x2;For'CreateProcessWithLogonW' -> dwCreationFlagsGlobal Const $CREATE_DEFAULT_ERROR_MODE = 0x4000000;Les initialisationsDim $STARTUPINFO = "",$si=""Dim $PROCESS_INFORMATION ="",$pi="";$STARTUPINFO &= "dword cb;long lpReserved;long lpDesktop;long lpTitle;dword dwX;dword dwY;"$STARTUPINFO &= "dword dwXSize;dword dwYSize;dword dwXCountChars;dword dwYCountChars;"$STARTUPINFO &= "dword dwFillAttribute;dword dwFlags;short wShowWindow;short cbReserved2;long lpReserved2;"$STARTUPINFO &= "long hStdInput;long hStdOutput;long hStdError"$si = DllStructCreate($STARTUPINFO)If $si = 0 Then msg(@error) ExitEndIfDllStructSetData($si,"cb",DllStructGetSize($si))$ptrSI = DllStructGetPtr($si);~ Msg($ptrSI)$PROCESS_INFORMATION &= "long hProcess;long hThread;long dwProcessId;long dwThreadId"$pi = DllStructCreate($PROCESS_INFORMATION)If $pi = 0 Then msg(@error) ExitEndIf$ptrPI = DllStructGetPtr($pi);~ Msg($ptrPI)$arrRet = DllCall("advapi32.dll","long","CreateProcessWithLogonW", _ "wstr","user", _ "wstr","domain", _ "wstr","password", _ "dword",$LOGON_WITH_PROFILE, _ "wstr","", _ "wstr","c:\windows\notepad.exe", _ "dword",$CREATE_DEFAULT_ERROR_MODE, _ "ptr",0, _ "ptr",0, _ "ptr",$ptrSI, _ "ptr",$ptrPI)If Not @error and $arrRet[0]<>0 Then $arrRet = DllCall("kernel32.dll", "int", "CloseHandle", "ptr",DllStructGetPtr($pi,"dwProcessId")) If Not @error and $arrRet[0]<>0 Then Msg("Return of 'CloseHandle' : "& $arrRet[0]) Else Msg("Error (CloseHandle): "& @error) Msg("Return of 'CloseHandle' : "& $arrRet[0]) Exit 1 EndIfElse Msg("Error (CreateProcessWithLogonW) : "& @error) Msg("Return of 'CreateProcessWithLogonW' : "& $arrRet[0]) Exit 2EndIfExit 0;Func Msg($letexte) MsgBox(0x43000,"Message...",$letexte)EndFunccan anyone gelp me ? Yes i know the function RunAsSet(xx,xx.... etc...) but i want know why this function not work with AutoIt3 !!?Thanks...FourLCCPWLW.au3 Link to comment Share on other sites More sharing options...
arcker Posted January 20, 2008 Share Posted January 20, 2008 expandcollapse popupopt("RunErrorsFatal",0) opt("MustDeclareVars",0) #include<WinApi.au3> ;For 'CreateProcessWithLogonW' -> dwLogonFlags Global Const $LOGON_WITH_PROFILE = 0x1 Global Const $LOGON_NETCREDENTIALS_ONLY = 0x2 ;For'CreateProcessWithLogonW' -> dwCreationFlags Global Const $CREATE_DEFAULT_ERROR_MODE = 0x4000000 ;Les initialisations Dim $STARTUPINFO = "",$si="" Dim $PROCESS_INFORMATION ="",$pi="" ; $STARTUPINFO &= "dword cb;long lpReserved;long lpDesktop;long lpTitle;dword dwX;dword dwY;" $STARTUPINFO &= "dword dwXSize;dword dwYSize;dword dwXCountChars;dword dwYCountChars;" $STARTUPINFO &= "dword dwFillAttribute;dword dwFlags;short wShowWindow;short cbReserved2;long lpReserved2;" $STARTUPINFO &= "long hStdInput;long hStdOutput;long hStdError" $si = DllStructCreate($STARTUPINFO) If $si = 0 Then msg(@error) Exit EndIf DllStructSetData($si,"cb",DllStructGetSize($si)) $ptrSI = DllStructGetPtr($si) ;~ Msg($ptrSI) $PROCESS_INFORMATION &= "long hProcess;long hThread;long dwProcessId;long dwThreadId" $pi = DllStructCreate($PROCESS_INFORMATION) If $pi = 0 Then msg(@error) Exit EndIf $ptrPI = DllStructGetPtr($pi) ;~ Msg($ptrPI) $tCommandLine = DllStructCreate("char[256]") $ProcessName = "c:\Program Files\AutoIt3\Au3Info.exe" DllStructSetData($tCommandLine,1,$ProcessName) $arrRet = DllCall("advapi32.dll","long","CreateProcessWithLogonW", _ "wstr","username", _ "wstr","domain", _ "wstr","password", _ "dword",$LOGON_WITH_PROFILE, _ "wstr",$ProcessName, _ "ptr",DllStructGetPtr($tCommandLine), _ "dword",$CREATE_DEFAULT_ERROR_MODE, _ "ptr",0, _ "ptr",0, _ "ptr",$ptrSI, _ "ptr",$ptrPI) if $arrRet[0]=0 then MsgBox(0,"Error in Dllcall",_WinAPI_GetLastErrorMessage()) Exit EndIf If Not @error and $arrRet[0]<>0 Then $arrRet = DllCall("kernel32.dll", "int", "CloseHandle", "ptr",DllStructGetPtr($pi,"dwProcessId")) If Not @error and $arrRet[0]<>0 Then Msg("Return of 'CloseHandle' : "& $arrRet[0]) Else Msg("Error (CloseHandle): "& @error) Msg("Return of 'CloseHandle' : "& $arrRet[0]) Exit 1 EndIf Else Msg("Error (CreateProcessWithLogonW) : "& @error) Msg("Return of 'CreateProcessWithLogonW' : "& $arrRet[0]) Exit 2 EndIf Exit 0 ; Func Msg($letexte) MsgBox(0x43000,"Message...",$letexte) EndFunc -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
FourLC Posted January 20, 2008 Author Share Posted January 20, 2008 Thank for our help ! But now i've an other error with the windows error code "1058" (In french : "Le service ne peut pas être démarré parce qu'il est désactivé ou qu'auncun périphérique activé ne lui est associé") ! I'm not sure but i've a PC with "Home XP" ("Windows Edition familliale") , not the "Pro" version of XP ! Maybe on "Home edition" of XP , we can't impersonate user or create process with "CreateProcessWithLogonW" !? I've modified my "Home XP" for having ACL on directory and other "Pro" features but it's not enough to impersonate !! Thanks for reply FourLC Link to comment Share on other sites More sharing options...
arcker Posted January 20, 2008 Share Posted January 20, 2008 mmmm please check that you have the service "secondary connexion" started (en francais : "connexion secondaire") to do so => start menu / Execute / services.msc if you don"t have any, then you can't launch a process with anoter account while a session is already started. -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
FourLC Posted January 21, 2008 Author Share Posted January 21, 2008 well, well, how to say......Just : excuse me...you're right and i'm very confuse !!One year ago, i'm walking through the web and i've found this trick (in french) : Désactiver les services inutilesBut, after a year, i've forgot this and my service "secondary connexion" ("Connexion secondaire") was disconnected !Excuse me for this !It's work fine !Thanks a lot ......FourLC Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now