Citation :
procedure WinExecAsUser(FileName: string; username: string; password: string; Visibility: integer);
var { V1 by Pat Ritchey, V2 by P.Below }
zAppName : array[0..512] of char;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
h : thandle;
begin
StrPCopy(zAppName, FileName);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not LogonUser(pchar(username), '.', pchar(Password),LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, h) then
ShowMessage(SysErrorMessage(GetLastError));
CreateProcessAsUser(h, nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo); { pointer to PROCESS_INF }
if GetLastError <> 0 then ShowMessage(SysErrorMessage(GetLastError));
end;
|