Einzelnen Beitrag anzeigen

Benutzerbild von Moombas
Moombas

Registriert seit: 22. Mär 2017
Ort: bei Flensburg
525 Beiträge
 
FreePascal / Lazarus
 
#18

AW: Passwort automatisch eingeben

  Alt 11. Aug 2020, 07:19
Also ich mache da aktuell so (allerdings in Lazarus):

Delphi-Quellcode:
//Oberhalb des "implementation" Bereichs
function CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword: LPWSTR; dwLogonFlags: dword; lpApplicationName,
  lpCommandLine: LPWSTR; dwCreationFlags: dword; lpEnvironment: pointer; lpCurrentDirectory: LPWSTR; lpStartupInfo:
  PStartUpInfoW; lpProcessInfo: PProcessInformation): boolean; stdcall; external 'advapi32.dll';
Delphi-Quellcode:
//Im "implementatrion" Bereich
//Prozess als bestimmten Benutzer starten
function CreateProcessAsLogon(const User, PW, Application, param, CmdLine: WideString): DWORD;
var
  ws : WideString;
  si : TStartupInfoW;
  pif : TProcessInformation;
begin
  ZeroMemory(@si, sizeof(si));
  si.cb := sizeof(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := 1;

  if CmdLine = 'then
  begin
    ws := Application;
  end else
  begin
    ws := Application + ' "' + CmdLine + '"';
  end;

  SetLastError(0);
  SI.cb := SizeOf(TStartupInfo);
  if CreateProcessWithLogonW(PWideChar(User), nil, PWideChar(PW), 0, nil, PWideChar(ws), CREATE_DEFAULT_ERROR_MODE, nil, PWideChar(param), @si, @pif) then
  begin
    sleep(500);
    if PIf.dwProcessId > 0 then
    begin
      AppPID := PIf.dwProcessId;
      CloseHandle(PIf.hProcess);
      CloseHandle(PIf.hThread);
    end;
  end;
  Result := GetLastError;
end;
Der Weg ist das Ziel aber man sollte auf dem Weg niemals das Ziel aus den Augen verlieren.

Geändert von Moombas (11. Aug 2020 um 07:24 Uhr)
  Mit Zitat antworten Zitat