function RunWait(FileName: string; Visibility: Integer): THandle;
var
zAppName: array[0..512] of Char;
zCurDir: array[0..255] of Char;
WorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
try
StrPCopy(zAppName, FileName);
GetDir(0, WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil, zAppName, nil, nil, false, Create_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
begin
result := 0;
Exit;
end
else
begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, result);
end;
finally
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunWait( '"C:\Program Files\UnrarDLL\Examples\Delphi\unrdll.exe" X "C:\Program Files\UnrarDLL\Examples\Delphi\demo.rar"', 0 );
{
aa:= ShellExecute(handle, 'open','"C:\Program Files\UnrarDLL\Examples\Delphi\unrdll.exe"',
'x "C:\Program Files\UnrarDLL\Examples\Delphi\demo.rar"',nil, SW_HIDE); // SW_SHOWNORMAL);
}
ShowMessage('aa');
end;
等待一个进程结束,调用外部exe
最新推荐文章于 2022-06-24 10:01:58 发布