Einzelnen Beitrag anzeigen

MathiasSimmack
(Gast)

n/a Beiträge
 
#10

Re: Rückgabewert von CreateProcessWithLogonW und GetLastErro

  Alt 22. Jan 2005, 13:49
Feucht auch noch. Tja, keine Ahnung. Ich habe nur Delphi 5 und musste den ganzen Plunder daher selbst deklarieren, aber ich sehe die gewünschte Fehlermeldung, weil "xxx" natürlich nicht mein Admin-Kennwort ist. Hier der Code (die "DisplayErrorMsg"-Prozedur müsstest du kennen)
Delphi-Quellcode:
type
  _STARTUPINFOW = record
    cb: DWORD;
    lpReserved: Pointer;
    lpDesktop: Pointer;
    lpTitle: Pointer;
    dwX: DWORD;
    dwY: DWORD;
    dwXSize: DWORD;
    dwYSize: DWORD;
    dwXCountChars: DWORD;
    dwYCountChars: DWORD;
    dwFillAttribute: DWORD;
    dwFlags: DWORD;
    wShowWindow: Word;
    cbReserved2: Word;
    lpReserved2: PByte;
    hStdInput: THandle;
    hStdOutput: THandle;
    hStdError: THandle;
  end;
  TStartUpInfoW = _STARTUPINFOW;
  PStartUpInfoW = ^_STARTUPINFOW;
const
  LOGON_WITH_PROFILE = $00000001;

function CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword: PWideChar;
  dwLogonFlags: dword; lpApplicationName, lpCommandLine: PWideChar;
  dwCreationFlags: dword; lpEnvironment: pointer;
  lpCurrentDirectory: PWideChar; lpStartupInfo: PStartUpInfoW;
  lpProcessInfo: PProcessInformation): boolean; stdcall;
  external 'advapi32.dll';

procedure DisplayErrorMsg(wnd: HWND);
var
  buf : array[0..MAX_PATH]of char;
begin
  ZeroMemory (@buf,sizeof(buf));
  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,nil,GetLastError,0,buf,
    sizeof(buf),nil);
  MessageBox (wnd,buf,nil,MB_OK or MB_ICONSTOP);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  si : TStartupInfoW;
  pif : TProcessInformation;
  res : boolean;
begin
  ZeroMemory(@si,sizeof(si));
  si.cb := sizeof(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := 1;

  res := CreateProcessWithLogonW('Administrator',nil,
    'xxx',LOGON_WITH_PROFILE,nil,
    'rollup.exe',
    CREATE_DEFAULT_ERROR_MODE,nil,nil,@si,@pif);

  if(not res) then DisplayErrorMsg(self.Handle);
end;
Das Test-OS war XP SP2.
  Mit Zitat antworten Zitat