Re[4]: Проблемы с CreateProcessWithLogonW
От: ДмитрийК  
Дата: 18.06.03 12:19
Оценка:
Я пишу на Delphi, вот код

function Run(const cl:string; isWait: TWait = Wait;
              const user: string = ''; const password: string = '';
              const domain: string = ''): DWORD;
var
  si: STARTUPINFO;
  pi: PROCESS_INFORMATION;
  cline: array [0..1000] of WideChar;
  u, p, d: array [0..100] of WideChar;
  Ok: boolean;
begin
  ZeroMemory(@si, sizeof(si));
  si.cb := sizeof(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := SW_HIDE;
  si.lpDesktop := PChar('WinSta0\Default');
  ZeroMemory(@pi, sizeof(pi));
  if user <> '' then
    Ok := CreateProcessWithLogonW( StringToWideChar(user,u,100),
                                  StringToWideChar(domain,d,100),
                                  StringToWideChar(password,p,100),
                                  1, nil,
                                  StringToWideChar(cl,cline,1000),
                                  0, nil, nil, si, pi)
  else
    Ok := CreateProcess( nil, PChar(cl), nil, nil, false, 0, nil, nil, si, pi );
  if not Ok then
    raise Exception.Create('Fatal error. CreateProcess '+cl);
  if isWait = Wait then
    if WaitForSingleObject( pi.hProcess, INFINITE ) = WAIT_FAILED then
      raise Exception.Create('Fatal error. WaitForSingleObject '+cl);
  if not GetExitCodeThread(pi.hThread,Result) then
    raise Exception.Create('Fatal error. GetExitCodeThread '+cl);
  if Result <> 0 then
    Log.Write('Error', 'ExitCode = '+IntToStr(Result), '', '', '');
  CloseHandle( pi.hProcess );
  CloseHandle( pi.hThread );
end;
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.