Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Win XP: CreateProcessAsUser: Errorcode 1314 (https://www.delphipraxis.net/95944-win-xp-createprocessasuser-errorcode-1314-a.html)

Udontknow 16. Jul 2007 13:54


Win XP: CreateProcessAsUser: Errorcode 1314
 
Hallo allesamt,

ich habe folgende Funktion, die eine Applikation unter einem bestimmten Benutzerkontext ausführen soll:

Delphi-Quellcode:
function RunProcess(ExePath:String;Param:String;Username,Domain,Password:String):Cardinal;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
var TokenHandle:Cardinal;
begin
  Result:=0;

  //Existiert dieses File?
  if not FileExists(ExePath) then
    raise Exception.CreateFmt('File "%s" existiert nicht!',[ExePath]);

  //User anmelden und Token erhalten
  if not LogOnUser(PChar(Username),PChar(Domain),PChar(Password),LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,TokenHandle) then
    raise Exception.CreateFmt('LogonUser fehlgeschlagen! Errorcode: %d',[GetLastError]);

  //StartupInfo-Struktur initialisieren
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);

  //Werte zuweisen
  StartupInfo.cb         := SizeOf(StartupInfo);
  StartupInfo.dwFlags    := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := SW_SHOW;

  //Prozess starten
  if not CreateProcessAsUser(
    TokenHandle,
    @ExePath[1],
    NIL,
    NIL,
    NIL,
    True,
    NORMAL_PRIORITY_CLASS,
    NIL,
    NIL,
    StartupInfo,
    ProcessInfo)
  then
    raise Exception.CreateFmt('CreateProcessAsUser für "%s" fehlgeschlagen! Errorcode: %d',[ExePath,GetLastError]);

  //Auf Beendigung warten
  WaitForSingleObject(ProcessInfo.hProcess, INFINITE);

  //Exitcode des Prozesses ermitteln
  GetExitCodeProcess(ProcessInfo.hProcess, Result);

  //Handles freigeben
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;
Beim Aufruf einer Beispiel-Applikation erhalte ich jedoch grundsätzlich bei CreateProcessAsUser den Errorcode 1314 (ERROR_PRIVILEGE_NOT_HELD) geliefert. Dabei ist der verwendete Benutzer genau der gleiche, unter dem ich normal arbeite. Wenn ich das Programm so ausführen kann, sollte es doch auch bei CreateProcessAsUser klappen. Was also fehlt, was ist falsch?

Für Ideen wäre ich echt dankbar.

Bis dann,

Andreas

Luckie 16. Jul 2007 14:00

Re: Win XP: CreateProcessAsUser: Errorcode 1314
 
Zitat:

Zitat von Widows SDK
Windows 2000: The process calling LogonUser requires the SE_TCB_NAME privilege. If the calling process does not have this privilege, LogonUser fails and GetLastError returns ERROR_PRIVILEGE_NOT_HELD.

Dieses Privileg habe in der Regel nur Systemprozesse.

Und
Zitat:

The account specified by lpszUsername, must have the necessary account rights. For example, to log on a user with the LOGON32_LOGON_INTERACTIVE flag, the user (or a group to which the user belongs) must have the SE_INTERACTIVE_LOGON_NAME account right. For a list of the account rights that affect the various logon operations, see Account Rights Constants.
Nimm stattdessen CreateProcessWithLogonW:
http://www.michael-puff.de/Developer...thLogonW.shtml

Udontknow 16. Jul 2007 14:04

Re: Win XP: CreateProcessAsUser: Errorcode 1314
 
Aber bei mir bricht ja eben nicht LogonUser mit dieser Meldung ab, sondern CreateProcessAsUser.

CreateProcessWithLogonW finde ich gar nicht in der Windows-Unit. Ist das nicht eine .NET-Routine?

Edit: Okay, schnappe mir mal deinen Code. Danke erstmal! :)

Cu,
Udontknow

Udontknow 16. Jul 2007 15:33

Re: Win XP: CreateProcessAsUser: Errorcode 1314
 
So, habe deine Routine getestet.

Grundsätzlich funktioniert CreateProcessWithLogonW, ABER:

Ich habe bei diesem Aufruf nicht die Möglichkeit, die Konsolenapplikation (um solche geht es hier) in derselben Konsole wie die des aufrufenden Programms laufen zu lassen, es wird immer eine neue Applikationskonsole erzeugt, egal, was ich bei CreationFlags mitgebe.
Zitat:

dwCreationFlags
[in] The flags that control how the process is created. The CREATE_DEFAULT_ERROR_MODE, CREATE_NEW_CONSOLE, and CREATE_NEW_PROCESS_GROUP flags are enabled by default— even if you do not set the flag, the system functions as if it were set. You can specify additional flags as noted.
Ich benötige unbedingt dieselbe Konsole (der Text der Konsole wird an ein Scheduling-System geschleust, ohne die entsprechenden Textausgaben sind die Leute, die das System betreuen, völlig aufgeschmissen, wenn etwas passiert).

Ich denke, daß CreateProcessAsUser da schon richtig ist, aber ich muss eben nun herausfinden, welches Privileg denn genau nun fehlt. Irgendjemand noch eine Idee?

Bis dann,

Andreas


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz