如何在程序中关闭其他外部运行的程序?(50分)

  • 主题发起人 主题发起人 zhbj
  • 开始时间 开始时间
Z

zhbj

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在程序中关闭其他外部正在运行的程序?
 
SendMessage(FindWindow(nil,窗口标题), WM_CLOSE, 0, 0);
 
如果其他程序是有窗口的话,可以发一个WM_QUIT消息,没窗体我没有办法:)
 
//获得进程列表,并终止 Excel 进程<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; FSnapshotHandle:THandle;<br>&nbsp; FProcessEntry32:TProcessEntry32;<br>&nbsp; Ret : BOOL;<br>&nbsp; ProcessID : integer;<br>&nbsp; s:string;<br>begin<br>&nbsp; FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br>&nbsp; Ret:=Process32First(FSnapshotHandle,FProcessEntry32);<br>&nbsp; Memo1.clear;<br>&nbsp; while Ret do<br>&nbsp; begin<br>&nbsp; &nbsp; Memo1.lines.add(FProcessEntry32.szExeFile);<br>&nbsp; &nbsp; s:=ExtractFileName(FProcessEntry32.szExeFile);<br>&nbsp; &nbsp; if s='EXCEL.EXE' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ProcessID:=FProcessEntry32.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,ProcessID),1);<br>&nbsp; &nbsp; &nbsp; s:='';<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Ret:=Process32Next(FSnapshotHandle,FProcessEntry32);<br>&nbsp; end;<br>end;<br>
 
TProcessEntry32为何物??
 
uses TLHelp32;
 
多人接受答案了。
 
能不能获得远程计算机的进程列表呀????
 
后退
顶部