求助!一个棘手的问题,关于关闭外部程序!!! ( 积分: 50 )

  • 主题发起人 主题发起人 Miros
  • 开始时间 开始时间
M

Miros

Unregistered / Unconfirmed
GUEST, unregistred user!
用sendmessage关闭外部程序,但是这个程序在关闭的时候会弹出一个确认关闭的对话框,不点就关不掉。但是又不能使用结束进程的方法,因为这个程序在关闭的时候是要保存数据的。请问改怎么做?
 
用sendmessage关闭外部程序,但是这个程序在关闭的时候会弹出一个确认关闭的对话框,不点就关不掉。但是又不能使用结束进程的方法,因为这个程序在关闭的时候是要保存数据的。请问改怎么做?
 
查找那个弹出窗口的句柄,然后查找Close按钮的句钮,向按钮发消息
 
同意njxdh意见
 
我也知道原理但是不知道怎么做啊?能不能给段相应的代码?
 
晕,先让软件保存数据,然后直接关闭进程。<br><br>//进程结构<br> &nbsp;TProcessInfo=Record<br> &nbsp; &nbsp; &nbsp; &nbsp;ExeFileName:String;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProcessID:DWord;<br> &nbsp;end;<br>//关闭进程processname<br>function FindProcess(processname: string): boolean;<br>var<br> &nbsp; &nbsp; &nbsp; &nbsp;p:TProcessInfo;<br> &nbsp; &nbsp; &nbsp; &nbsp;OK:Bool;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProcessListHandle:THandle;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProcessStruct:TProcessEntry32;<br>begin <br> &nbsp; &nbsp; &nbsp; &nbsp;result:=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProcessListHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);<br> &nbsp; &nbsp; &nbsp; &nbsp;ProcessStruct.dwSize:=SizeOf(ProcessStruct);<br> &nbsp; &nbsp; &nbsp; &nbsp;OK:=Process32First(ProcessListHandle,ProcessStruct);<br> &nbsp; &nbsp; &nbsp; &nbsp;while Integer(OK)&lt;&gt;0 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p.ExeFileName:=ProcessStruct.szExeFile;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p.ProcessID:=ProcessStruct.th32ProcessID;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OK:=Process32Next(ProcessListHandle,ProcessStruct);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if uppercase(p.ExeFileName)=uppercase(processname) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;showmessage('p.ProcessID:'+inttostr(p.ProcessID));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;terminateprocess(p.ProcessID,0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//进程标识不是进程句柄<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result:=true;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;closehandle(ProcessListHandle);<br>end;<br><br>function KillTask(ExeFileName: string): integer;<br>const<br> &nbsp;PROCESS_TERMINATE=$0001;<br>var<br> &nbsp;ContinueLoop: BOOL;<br> &nbsp;FSnapshotHandle: THandle;<br> &nbsp;FProcessEntry32: TProcessEntry32;<br>begin<br> &nbsp;result := 0;<br><br> &nbsp;FSnapshotHandle := CreateToolhelp32Snapshot<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (TH32CS_SNAPPROCESS, 0);<br> &nbsp;FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br> &nbsp;ContinueLoop := Process32First(FSnapshotHandle,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FProcessEntry32);<br><br> &nbsp;while integer(ContinueLoop) &lt;&gt; 0 do<br> &nbsp;begin<br> &nbsp; &nbsp;if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =<br> &nbsp; &nbsp; &nbsp; &nbsp; UpperCase(ExeFileName))<br> &nbsp; &nbsp; or (UpperCase(FProcessEntry32.szExeFile) =<br> &nbsp; &nbsp; &nbsp; &nbsp; UpperCase(ExeFileName))) then<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;showmessage('FProcessEntry32.th32ProcessID:'+inttostr(FProcessEntry32.th32ProcessID));<br> &nbsp; &nbsp; &nbsp; &nbsp;showmessage('OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID):'+inttostr(OpenProcess(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PROCESS_TERMINATE, BOOL(0),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FProcessEntry32.th32ProcessID)));<br> &nbsp; &nbsp; &nbsp; &nbsp;Result := Integer(TerminateProcess(OpenProcess( &nbsp; &nbsp; &nbsp;//进程句柄通过OpenProcess获得<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PROCESS_TERMINATE, BOOL(0),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FProcessEntry32.th32ProcessID), 0)); //关闭进程<br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp;ContinueLoop := Process32Next(FSnapshotHandle,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FProcessEntry32);<br> &nbsp;end;<br> &nbsp;CloseHandle(FSnapshotHandle); <br><br>end;
 
请问<br>TProcessEntry32引用哪个单元?
 
uses tlhelp32就可以了<br>仁兄杀icesword试试看(^_^想了N多的办法就是kill不掉~)
 
看看我的笔记<br>宇宙中最强悍的关闭进程代码<br>这篇
 
后退
顶部