Thema: Delphi CreateProcessAsUser

Einzelnen Beitrag anzeigen

microtronx

Registriert seit: 8. Mär 2005
Ort: Tapfheim
55 Beiträge
 
Delphi 2010 Enterprise
 
#6

Re: CreateProcessAsUser

  Alt 9. Apr 2006, 22:21
Hallo Renekr,

probier mal folgendes:

Delphi-Quellcode:
function WinExecAsUser(FileName, Commandline: string; domain:string; username: string; password:string; Visibility:integer; var errormessage:string):boolean;
var
        StartupInfo : _startupinfow;
        ProcessInfo : TProcessInformation;
        h : thandle;
        vtmp : string;
        wcurdir, wfilename, wcommandline, wdomain, wusername, wpassword:pwidechar;
begin
        GetStartupInfoW(startupinfo);
        FillChar(StartupInfo, Sizeof(StartupInfo), #0);
        StartupInfo.cb := Sizeof(StartupInfo);
        StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
        StartupInfo.wShowWindow := Visibility;
        // if not LogonUser(pchar(username), pchar(domain), pchar(Password),LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT, h) then ShowMessage(SysErrorMessage(GetLastError));

        vtmp:=extractfilepath(filename);
        GetMem( wcurdir, length(vtmp) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;
        StringToWideChar( vtmp, wcurdir, Length( vtmp ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;

        commandline:=' '+trim(trim(filename)+' '+trim(commandline));
        filename:='';

        GetMem( wpassword, length(password) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;
        GetMem( wusername, length(username) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;
        GetMem( wdomain, length(domain) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;
        GetMem( wFileName, length(FileName) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;
        GetMem( wCommandline, length(Commandline) * SizeOf( WideChar ) + SizeOf(WideChar ) ) ;

        StringToWideChar( password, wpassword, Length( password ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;
        StringToWideChar( username, wusername, Length( username ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;
        StringToWideChar( domain, wdomain, Length( domain ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;
        StringToWideChar( FileName, wFileName, Length( FileName ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;
        StringToWideChar( Commandline, wCommandline, Length( Commandline ) * SizeOf(WideChar ) + SizeOf( WideChar ) ) ;

        result:=false; errormessage:='';

        result:=CreateProcessWithLogonW(wusername,wdomain,wpassword,0, nil, wcommandline,0, nil, wcurdir,StartupInfo , ProcessInfo);
        if result=false then errormessage:=sysErrorMessage(Getlasterror);
end;
Das hatte ich mir irgendwann mal zusammengestellt und ich glaube das das auch funktioniert hat. Probiers einfach.

Mfg.
Yusuf Zorlu
yusuf.zorlu@microtronx.com

Meine Arbeit ist so geheim ... ich habe selbst keine Ahnung was ich überhaupt mache!
  Mit Zitat antworten Zitat