procedure ShellExecAndWait(sExe, sCommandLine, sWorkDir: string;
Wait, Freeze: Boolean; Show: Boolean = True);
var
exInfo: TShellExecuteInfo;
Ph: DWORD;
WorkDir: PChar;
begin
if sWorkDir = '' then
WorkDir := nil
else
WorkDir := PChar(WorkDir);
FillChar(exInfo, sizeof(exInfo), 0);
with exInfo do
begin
cbSize := sizeof(exInfo);
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := GetActiveWindow();
exInfo.lpVerb := 'open';
exInfo.lpParameters := PChar(sCommandLine);
lpFile := PChar(sExe);
lpDirectory := WorkDir;
nShow := SW_SHOW;
end;
if ShellExecuteEx(@exInfo) then
Ph := exInfo.hProcess
else
begin
exit;
end;
if Wait then
while WaitForSingleObject(exInfo.hProcess, 0) <> WAIT_OBJECT_0 do
begin
if Freeze = false then
Sleep(1);
end;
CloseHandle(Ph);
end;
2. You can call bat file in cmd like:
Open in new window