Einzelnen Beitrag anzeigen

venice2
(Gast)

n/a Beiträge
 
#7

AW: CreateProcess wirft Kernelbase Error

  Alt 2. Apr 2021, 15:40
Ich hatte oben noch bissl was geändert. pps:

Vorallem siehe "Tipp"
Habe ich

Delphi-Quellcode:
function PipeExec(CommandLine, Path: String; EnvironementStrings: PChar; var StdIO: TStdIO; UserToken: THandle; ShowWindow: DWORD = SW_HIDE): TProcessInformation;
const
  ProcessCreationFlags: DWord = NORMAL_PRIORITY_CLASS;
var
  SI : TStartupInfo;
  PathPChar : PChar;
begin
  // initialize the structure we are going to use
  Zeromemory(@SI, SizeOf(SI));
  Zeromemory(@result, SizeOf(result));
  // Fill the necessary fields
  SI.cb := sizeof(SI); // Size of the structure. The OS uses that to validat it
  SI.dwFlags := STARTF_USESHOWWINDOW   or // Use the wShowWindow field
                 STARTF_USESTDHANDLES; // use the handles we created for the std IO pipes
  SI.wShowWindow := ShowWindow; // Show the console or not...
  SI.hStdError := StdIO.stdError.hWrite; // Write errors to the error pipe
  SI.hStdInput := StdIO.stdIn.hRead; // read input from input pipe
  SI.hStdOutput := StdIO.stdOut.hWrite; // Write Ouput to output pipe

  if length(path) > 0 then
     PathPChar := PChar(Path)
  else
      PathPChar := nil;

  UniqueString(CommandLine); //<<<<<<< Hier!

  if UserToken = 0 then
  begin
    if not CreateProcess( nil, // must be NIL for win16 apps under NT, including DOS progs
                   pchar(CommandLine),
                   nil, // Process security attibutes. Sue same as current
                   nil, // Thread security attibutes. Sue same as current
                   true, // Inherite handles. Must be true for IO redirection
                   ProcessCreationFlags, // creation flags
                   EnvironementStrings, // If using with a CGI aplication, you MUST pass the HTTP headers as env. strings in this variable
                   PathPChar, // Directory of the new process
                   SI, // SISTEMINFO Structure used to initialize the new process
                   result) // PROCESINFORMATION structure used to control the newly created process
    then
      RaiseLastOSError;
  end
  else
  begin
    if not CreateProcessAsUser( UserToken, // UserToken of desired user. That token must be retreived with LogonUser or DuplicatteToken from a Impersonation token
                         nil, // must be NIL for win16 apps under NT, including DOS progs
                         pchar(CommandLine),
                         nil, // Process security attibutes. Sue same as current
                         nil, // Thread security attibutes. Sue same as current
                         true, // Inherite handles. Must be true for IO redirection
                         ProcessCreationFlags, // creation flags
                         EnvironementStrings, // If using with a CGI aplication, you MUST pass the HTTP headers as env. strings in this variable
                         PathPChar, // Directory of the new process
                         SI, // SISTEMINFO Structure used to initialize the new process
                         result) // PROCESINFORMATION structure used to control the newly created process
    then
      RaiseLastOSError;
  end;
end;
  Mit Zitat antworten Zitat