Mega Code Archive

 
Categories / Delphi / System
 

Run a process in the security context of another user

uses JwaWinBase; ( http://members.chello.nl/m.vanbrakel2/ ) //... procedure TForm1.Button1Click(Sender: TObject); var si: STARTUPINFOW; pif: PROCESS_INFORMATION; res: Bool; s: string; begin //erstmal die StartUpInfoW setzen //set StartUpInfoW first si.cb := SizeOf(startupinfow); si.dwFlags := STARTF_USESHOWWINDOW; si.wShowWindow := SW_SHOWDEFAULT; si.lpReserved := nil; si.lpDesktop := nil; si.lpTitle := 'Konsole'; // dann CreateProcessWithLogonW ausführen... // run CreateProcessWithLogonW... res := CreateProcessWithLogonW('Security', 'ArViCor', 'test', LOGON_WITH_PROFILE, 'c:\win2kas\system32\regedt32.exe', nil , CREATE_DEFAULT_ERROR_MODE, nil, nil, si, pif); if booltostr(res) = '0' then begin //wenn ein Fehler auftritt, soll der Fehlercode ausgegeben werden //über 'net helpmsg ' in der Kommandoeingabeaufforderung //kann dieser entziffert werden //if an error occures, show the error-code //this code can be 'translated' with 'net helpmsg ' on command-prompt str(GetLastError, s); ShowMessage('CreateProcessWithLogonResult: ' + booltostr(res) + #10 + 'GetLastError: ' + s); end; end; // Verbesserungen gerne als Mail an mich!