本文整理自网络,侵删。
uses Winapi.ShellAPI;
{ Runs application using ShellExecuteEx and waits for completion. }function ShellExecuteAndWait(FileName: String; Params: String): Boolean;var exInfo: TShellExecuteInfo; Ph: DWORD;begin 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(Params); lpFile := PChar(FileName); nShow := SW_SHOWNORMAL; end; if ShellExecuteEx(@exInfo) then Ph := exInfo.hProcess else begin ShowMessage(SysErrorMessage(GetLastError)); Result := true; exit; end; while WaitForSingleObject(exInfo.hProcess, 50) <> WAIT_OBJECT_0 do Application.ProcessMessages; CloseHandle(Ph); Result := true;end;
procedure TForm1.FormCreate(Sender: TObject);begin
ShellExecuteAndWait('regedit.exe','');
end;
相关阅读 >>
Delphi �c 如何将多个文件扩展名传递给tdirectory.getfiles?
Delphi 为当前窗口客户区捉图: getformimage
Delphi http协议验证访问datasnap rest 服务器
Delphi 解析Delphi中的loadlibrary,getprocaddress,freelibrary
更多相关阅读请进入《Delphi》频道 >>