求关闭进程的API函数!(30分)

  • 主题发起人 主题发起人 lynch2611
  • 开始时间 开始时间
L

lynch2611

Unregistered / Unconfirmed
GUEST, unregistred user!
在一个程序里想用API函数关闭另一个正在运行的程序。谢谢指点!
 
procedure KillCommandProcess;<br>var<br> ProcessSnapShotHandle: THandle;<br> ProcessEntry: TProcessEntry32;<br> ProcessHandle: THandle;<br> Ret: BOOL;<br>begin<br> ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> if ProcessSnapShotHandle&gt;0 then<br> begin<br> &nbsp; ProcessEntry.dwSize:=SizeOf(TProcessEntry32);<br> &nbsp; Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);<br> &nbsp; while Ret do<br> &nbsp; begin<br> &nbsp; &nbsp; if ProcessEntry.szExeFile='EXCEL.EXE' then //你要关闭的程序 注意:大小写敏感<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; ProcessHandle:=OpenProcess(PROCESS_TERMINATE, False,<br> &nbsp; &nbsp; &nbsp; &nbsp; ProcessEntry.th32ProcessID);<br> &nbsp; &nbsp; &nbsp; if ProcessHandle&gt;0 then<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; TerminateProcess(ProcessHandle, 0);<br> &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(ProcessHandle)<br> &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp; Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)<br> &nbsp; end;<br> &nbsp; CloseHandle(ProcessSnapShotHandle)<br> end<br>end;
 
谢谢!我试下!!
 
Undeclared identifier:'TProcessEntry32'<br>怎么解决啊??谢谢!!
 
uses<br> &nbsp;TlHelp32
 
太感谢啦!!!!!!!!!!!!
 
后退
顶部