Einzelnen Beitrag anzeigen

lukdelphias

Registriert seit: 23. Jun 2020
50 Beiträge
 
Delphi 10.3 Rio
 
#13

AW: Passwort automatisch eingeben

  Alt 10. Aug 2020, 14:13
Nur das habe ich bisher probiert:
Delphi-Quellcode:
program runadmin;

{$APPTYPE CONSOLE}

uses
  System, SysUtils, JwaWinBase;

var
  si: STARTUPINFOW;
  pif: PROCESS_INFORMATION;
  res: Boolean;
  s: string;
  cmd: PWideChar;
begin
  if Length(ParamStr(1)) = 0 then
    WriteLn(
      'RunAdmin - Kommando unter Administrator-Konto ausführen' + #13#10 +
      'Usage: runadmin <command>')
  else
  try
    si.cb := SizeOf(startupinfow);
    si.dwFlags := STARTF_USESHOWWINDOW;
    si.wShowWindow := 1;
    si.lpReserved := nil;
    si.lpDesktop := nil;
    si.lpTitle := 'Konsole';
    getmem(cmd,Length(ParamStr(1))*2);
    cmd := StringToWideChar(ParamStr(1),cmd,Length(ParamStr(1))*2);
    res := CreateProcessWithLogonW('Administrator', '', 'password', LOGON_WITH_PROFILE,
      nil,cmd,CREATE_DEFAULT_ERROR_MODE, nil, nil, si, pif);
    if booltostr(res) = '0then
    begin
      str(GetLastError, s);
      WriteLn('Beim Ausfuehren des Befehls "' + ParamStr(1) + '"');
      WriteLn('ist der Fehler ' + s + ' aufgetreten.');
      Halt(1);
    end;
  except
    on E: Exception do
    begin
      WriteLn('Beim Ausfuehren des Befehls "' + ParamStr(1) + '"');
      WriteLn('ist der Fehler ' + E.Message + ' aufgetreten.');
      Halt(1);
    end;
  end;

end.
Das ist ein angeblich lauffähiges Beispiel aus einem anderen Thema. Funktioniert bei mir leider nicht.
  Mit Zitat antworten Zitat