AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Rückgabewert von CreateProcessWithLogonW und GetLastError
Thema durchsuchen
Ansicht
Themen-Optionen

Rückgabewert von CreateProcessWithLogonW und GetLastError

Ein Thema von Luckie · begonnen am 19. Jan 2005 · letzter Beitrag vom 24. Jan 2005
 
Benutzerbild von Luckie
Luckie

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

Re: Rückgabewert von CreateProcessWithLogonW und GetLastErro

  Alt 22. Jan 2005, 19:24
Hm meine Versuche sehen jetzt so aus:
Delphi-Quellcode:
function CreateProcessAsLogon(const User, PW, Application, CmdLine: PWideChar):
  LongBool;
var
  si : TStartupInfoW;
  pif : TProcessInformation;
  AppCmdLine : PWideChar;
begin
  GetMem(AppCmdLine, length(Application) + length(CmdLine) + 3);
  try
    lstrcpyW(AppCmdLine, Application);
    lstrcatW(AppCmdLine, ' "');
    lstrcatW(AppCmdLine, CmdLine);
    lstrcatW(AppCmdLine, '"');
    ZeroMemory(@si, sizeof(si));
    si.cb := sizeof(si);
    si.dwFlags := STARTF_USESHOWWINDOW;
    si.wShowWindow := 1;

    result := CreateProcessWithLogonW(User, nil, PW,
      LOGON_WITH_PROFILE, nil, AppCmdLine,
      CREATE_DEFAULT_ERROR_MODE, nil, nil, @si, @pif);
  finally
    FreeMem(AppCmdLine);
  end;
end;
Anwendungen lassen sich mit und ohne Parameter starten, aber es kommt eine AV. Die Parameter werden als PWideChar(WideString(User)) übergeben.

Dann noch das:
Delphi-Quellcode:
function CreateProcessAsLogon(const User, PW, Application, CmdLine: WideString):
  LongBool;
var
  si : TStartupInfoW;
  pif : TProcessInformation;
  //AppCmdLine : PWideChar;
begin
// GetMem(AppCmdLine, length(Application) + length(CmdLine) + 3);
  try
// lstrcpyW(AppCmdLine, Application);
// lstrcatW(AppCmdLine, ' "');
// lstrcatW(AppCmdLine, CmdLine);
// lstrcatW(AppCmdLine, '"');
    ZeroMemory(@si, sizeof(si));
    si.cb := sizeof(si);
    si.dwFlags := STARTF_USESHOWWINDOW;
    si.wShowWindow := 1;

    result := CreateProcessWithLogonW(PWideChar(User), nil, PWideChar(PW),
      LOGON_WITH_PROFILE, nil, PWideChar(Application+' "'+CmdLine+'"'),
      CREATE_DEFAULT_ERROR_MODE, nil, nil, @si, @pif);
  finally
// FreeMem(AppCmdLine);
  end;
end;
Die Parameter werden ungecastet als Stringsübergeben. Da bekomme ich auch Anwendungen mit und ohne Parameter gestartet, aber bei falschen Passwort habe ich wieder GetLastError = 0:

Noch ein Versuch:
Delphi-Quellcode:
function CreateProcessAsLogon(const User, PW, Application, CmdLine: WideString):
  LongBool;
var
  si : TStartupInfoW;
  pif : TProcessInformation;
  WUser : WideString;
  WPW : WideString;
  WApp : WideString;
  WCmdLine : WideString;
begin
  ZeroMemory(@si, sizeof(si));
  si.cb := sizeof(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := 1;

  WUser := User;
  WPW := PW;
  WApp := Application;
  WCmdLine := CmdLine;

  result := CreateProcessWithLogonW(PWideChar(WUser), nil, PWideChar(WPW),
    LOGON_WITH_PROFILE, nil, PWideChar(WApp + ' "' + WCmdLine + '"'),
    CREATE_DEFAULT_ERROR_MODE, nil, nil, @si, @pif);
end;
False und GetLastError = 0.

Nächster Versuch:
Delphi-Quellcode:
function CreateProcessAsLogon(const User, PW, Application, CmdLine: PWideChar):
  LongBool;
var
  si : TStartupInfoW;
  pif : TProcessInformation;
  WUser : LPWSTR;
  WPW : LPWSTR;
  WApp : LPWSTR;
  WCmdLine : LPWSTR;
  AppCmd: LPWSTR;
begin
  ZeroMemory(@si, sizeof(si));
  si.cb := sizeof(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := 1;

  WUser := SysAllocString(User);
  WPW := SysAllocString(PW);
  WApp := SysAllocString(Application);
  WCmdLine := SysAllocString(CmdLine);
  GetMem(AppCmd, length(Application)+length(CmdLine)+3);
  lstrcpyW(AppCmd, WApp);
  lstrcatW(AppCmd, ' "');
  lstrcatW(AppCmd, CmdLine);
  lstrcatW(AppCmd, '"');

  result := CreateProcessWithLogonW(PWideChar(WUser), nil, PWideChar(WPW),
    LOGON_WITH_PROFILE, nil, AppCmd,
    CREATE_DEFAULT_ERROR_MODE, nil, nil, @si, @pif);
end;
False und GetLastError = 0. Bei Anwendungen mit Paramtern komt eine AV nach dem Start.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz