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