本文整理自网络,侵删。
//ShellAPIprocedure ExecuteWait(const sProgramm: string; const sParams: string = ''; fHide: Boolean = false); var ShExecInfo: TShellExecuteInfo; begin FillChar(ShExecInfo, sizeof(ShExecInfo), 0); with ShExecInfo do begin cbSize := sizeof(ShExecInfo); fMask := SEE_MASK_NOCLOSEPROCESS; lpFile := PChar(sProgramm); lpParameters := PChar(sParams); lpVerb := 'open'; if (not fHide) then nShow := SW_SHOW else nShow := SW_HIDE end; if (ShellExecuteEx(@ShExecInfo) and (ShExecInfo.hProcess <> 0)) then try WaitForSingleObject(ShExecInfo.hProcess, INFINITE) finally CloseHandle(ShExecInfo.hProcess); end;end;
procedure TForm1.Button1Click(Sender: TObject);beginExecuteWait('cmd.exe','',false);end;
相关阅读 >>
Delphi防止因系统崩溃而丢失任务栏的图标(重建托盘图标)
Delphi winapi: movewindow - 改变窗口的位置与大小
Delphi ifileoperation替换shfileoperation
更多相关阅读请进入《Delphi》频道 >>