Thema: Delphi CreateProcessAsUser

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#9

Re: CreateProcessAsUser

  Alt 18. Nov 2004, 11:34
Geht prima:
Delphi-Quellcode:
uses MpuWinNT;

function CreateProcessAsLogon(const User, PW, Application, CmdLine: WideString):
  Boolean;
var
  si : TStartupInfoW;
  pif : TProcessInformation;
begin
  si.cb := SizeOf(TStartupInfoW);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := 1;
  si.lpReserved := nil;
  si.lpDesktop := nil;
  si.lpTitle := nil;
  Result := CreateProcessWithLogonW(PWideChar(User), nil, PWideChar(PW),
    LOGON_WITH_PROFILE, nil, PWideChar(Application +' '+CmdLine),
    CREATE_DEFAULT_ERROR_MODE, nil, nil, si, pif);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  if not CreateProcessAsLogon('Administrator', 'passwort', 'Notepad.exe', 'c:\boot.ini') then
    RaiseLastOSError;
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat