我在调用"excel"时每次退出都会在进程中保留了一个"excel.exe"进程,请问各位大虾怎样杀死他.是不是用BOOL TerminateProcess( HANDLE hProcess, // handle to the process
UINT uExitCode // exit code for the process
);?
但我不太了解那两个参数是什么意识,hProcess怎样获得,请尽量详细点,谢谢!!!!
UINT uExitCode // exit code for the process
);?
但我不太了解那两个参数是什么意识,hProcess怎样获得,请尽量详细点,谢谢!!!!
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult); if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0); { Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
end;
UINT uExitCode // exit code for the process
);第一个参数是你要杀死的进程的句柄
第二个参数是退出的代码,一般是“0”
可以用GetExitCodeProcess 得到BOOL GetExitCodeProcess( HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // address to receive termination status
);楼上的答复应该可以帮你解决此问题