AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi CreateProcess + XCOPY + Pipes = HILFE!!!
Thema durchsuchen
Ansicht
Themen-Optionen

CreateProcess + XCOPY + Pipes = HILFE!!!

Ein Thema von FritzAT · begonnen am 25. Aug 2007 · letzter Beitrag vom 26. Aug 2007
 
FritzAT
(Gast)

n/a Beiträge
 
#3

Re: CreateProcess + XCOPY + Pipes = HILFE!!!

  Alt 25. Aug 2007, 22:18
Hallo!

Danke für die antwort, aber wie geschreiben funktionieren die anderen commandos
einwandfrei(dir /?,...).
Soweit muesste die funktion eigentlich mit XCOPY auch funktionieren.
Ich glaube bald es liegt an XCOPY selbst...
Zu deiner frage.
Die umleitung erfolg über eine temporäre datei...

Delphi-Quellcode:
function TForm1.RunCaptured(const _dirName, _exeName, _cmdLine: string): Boolean;
var
  start: TStartupInfo;
  procInfo: TProcessInformation;
  tmpName: string;
  tmp: Windows.THandle;
  tmpSec: TSecurityAttributes;
  res: TStringList;
  return: Cardinal;
begin
  Result := False;
  try
    { Setze ein Temporäres File }
    tmpName := 'Test.tmp';
    FillChar(tmpSec, SizeOf(tmpSec), #0);
    tmpSec.nLength := SizeOf(tmpSec);
    tmpSec.bInheritHandle := True;
    tmp := Windows.CreateFile(PChar(tmpName),
           Generic_Write, File_Share_Write,
           @tmpSec, Create_Always, File_Attribute_Normal, 0);
    try
      FillChar(start, SizeOf(start), #0);
      start.cb := SizeOf(start);
      start.hStdOutput := tmp;
      start.dwFlags := StartF_UseStdHandles or StartF_UseShowWindow;
      start.wShowWindow := SW_Minimize;
      { bsp. RunCaptured('C:\', 'cmd.exe', '/c dir /?'); }
      if CreateProcess
        (nil, // pointer to name of executable module
         PChar(_exeName+' '+_cmdLine), // pointer to command line string
         nil, // pointer to process security attributes
         nil, // pointer to thread security attributes
         True, // handle inheritance flag
         0, // creation flags
         nil, // pointer to new environment block
         PChar(_dirName), // pointer to current directory name
         start, // pointer to STARTUPINFO
         procInfo) // pointer to PROCESS_INFORMATION
      then
      begin
        SetPriorityClass(procInfo.hProcess, Idle_Priority_Class);
        WaitForSingleObject(procInfo.hProcess, Infinite);
        GetExitCodeProcess(procInfo.hProcess, return);
        Result := (return = 0);
        CloseHandle(procInfo.hThread);
        CloseHandle(procInfo.hProcess);
        Windows.CloseHandle(tmp);
        { Die Ausgaben hinzufügen }
        res := TStringList.Create;
        try
          res.LoadFromFile(tmpName);
          Memo1.Lines.AddStrings(res);
        finally
          res.Free;
        end;
        Windows.DeleteFile(PChar(tmpName));
      end
      else
      begin
        Application.MessageBox(PChar(SysErrorMessage(GetLastError())),
          'RunCaptured Error', MB_OK);
      end;
    except
      Windows.CloseHandle(tmp);
      Windows.DeleteFile(PChar(tmpName));
      raise;
    end;
  finally
  end;
end;
--------------------------------------
Delphi-Quellcode:
procedure TForm1.Button3Click(Sender: TObject);
begin
  RunCaptured('C:\', 'cmd.exe', '/c copy /?');
end;
  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 11: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