参考:http://hi.baidu.com/w304/blog/item/2ac3da3ed1838cf9828b13b1.html function ExecAppWait(AppName, Params: string): Boolean;var// Structure containing and receiving info about application to startShellExInfo: TShellExecuteInfo;beginFillChar(ShellExInfo, SizeOf(ShellExInfo), 0);with ShellExInfo do begin cbSize := SizeOf(ShellExInfo); fMask := see_Mask_NoCloseProcess; Wnd := Application.Handle; lpFile := PChar(AppName); lpParameters := PChar(Params); nShow := sw_ShowNormal;end;Result := ShellExecuteEx(@ShellExInfo);if Result then while WaitForSingleObject(ShellExInfo.HProcess, 100) = WAIT_TIMEOUT do begin Application.ProcessMessages; if Application.Terminated then Break; end;end;
在FORMCLOSE里遍历进程然后KILL掉
或 Windows.FindWindow(..) 然后发消息KILL掉
var h :HWND; // 变成全局变量就行了然后在FORMCLOSE事件里写上SendMessage(h, WM_CLOSE, 0, 0);
function ExecAppWait(AppName, Params: string): Boolean;var// Structure containing and receiving info about application to startShellExInfo: TShellExecuteInfo;beginFillChar(ShellExInfo, SizeOf(ShellExInfo), 0);with ShellExInfo do begin cbSize := SizeOf(ShellExInfo); fMask := see_Mask_NoCloseProcess; Wnd := Application.Handle; lpFile := PChar(AppName); lpParameters := PChar(Params); nShow := sw_ShowNormal;end;Result := ShellExecuteEx(@ShellExInfo);if Result then while WaitForSingleObject(ShellExInfo.HProcess, 100) = WAIT_TIMEOUT do begin Application.ProcessMessages; if Application.Terminated then Break; end;end;
h :HWND; // 变成全局变量就行了然后在FORMCLOSE事件里写上SendMessage(h, WM_CLOSE, 0, 0);