function PCharOrNil(
const AString:
string): PChar;
begin
if AString = '
'
then
Result :=
nil
else
Result := PChar(AString);
end;
function ShellExecAndWait(
const FileName, Directory, Parameters, Verb:
string; CmdShow: Integer): Boolean;
var
SEI: TShellExecuteInfo;
begin
FillChar(SEI, SizeOf(SEI), #0);
SEI.cbSize := SizeOf(SEI);
SEI.fMask := SEE_MASK_DOENVSUBST
or SEE_MASK_FLAG_NO_UI
or SEE_MASK_NOCLOSEPROCESS;
SEI.lpFile := PCharOrNil(FileName);
// Filename
SEI.lpDirectory := PCharOrNil(Directory);
// Directory
SEI.lpParameters := PCharOrNil(Parameters);
// Parameters
SEI.lpVerb := PCharOrNil(Verb);
// Verb
SEI.nShow := CmdShow;
// How display the CMD Window
Result := ShellExecuteEx(@SEI);
if Result
then
begin
WaitForInputIdle(SEI.hProcess, INFINITE);
WaitForSingleObject(SEI.hProcess, INFINITE);
CloseHandle(SEI.hProcess);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
const
Dcc32Path = '
D:\Users\xyz\Documents\RAD Studio\MyProjects\SetWinIcon\Debug\SetIcon.d\RC\cfg\dcc32.exe';
DprPath = '
D:\Users\xyz\AppData\Local\Temp\RC\justtest.dpr';
OutPutPath = '
D:\Users\xyz\Pictures';
begin
if ShellExecAndWait(Dcc32Path , OutPutPath , DprPath ,'
open', 1)
then
self.Color := clGreen
else
self.Color := clFuchsia;
end;