Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
Re: Rückgabewert eines Prozesses
26. Sep 2003, 01:26
Also darum geht es mir:
Delphi-Quellcode:
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD): Longword;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := ShowCmd;
if not CreateProcess(nil,
@Filename[1],
nil,
nil,
False,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo)
then
Result := WAIT_FAILED
else
begin
if wait = FALSE then
begin
if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
exit;
end;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
end;
if ProcessInfo.hProcess <> 0 then
CloseHandle(ProcessInfo.hProcess);
if ProcessInfo.hThread <> 0 then
CloseHandle(ProcessInfo.hThread);
end;
function GetExitCodeExpand(PID: LongWord): Integer;
var
hProcess: THandle;
Code: Cardinal;
begin
result := 0;
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION, False, PID);
if hProcess <> 0 then
begin
GetExitCodeProcess(hProcess, Code);
result := Code;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcID: Cardinal;
begin
RunProcess('expand i:\I386\xyz.CP_ d:\foo.sys', SW_SHOWNORMAL, True, @ProcID);
ShowMessage(IntToStr(GetExitCodeExpand(ProcID)));
end;
Ich bekomme immer 0 zurück, egal ob es die Datei auf der Windows CD gibt oder nicht.
Michael Ein Teil meines Codes würde euch verunsichern.
|
|
Zitat
|