怎样在windows中关闭所有进程?(100分)

  • 主题发起人 主题发起人 sakura12
  • 开始时间 开始时间
S

sakura12

Unregistered / Unconfirmed
GUEST, unregistred user!
[?][red][/red]怎样在windows中关闭所有进程?<br>
 
转(leebons)<br><br>下面是我写的一段源代码,只要你把你想要终止的程序名(包括路径)写入<br>D:/Program Files/text1.txt这个文件中(注意每行写一个程序名).那么这个<br>程序无法运行下去.程序里有详细的注释.祝你好运!<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,tlhelp32,stdCtrls, ExtCtrls;//注意加上tlhelp32这个单元;<br>type &nbsp; &nbsp; <br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; ListBox2: TListBox;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; private<br>&nbsp; procedure processlist(var prolist:tlist);//自定义函数列举所有的进程;<br>&nbsp; procedure exitcode ;//自定义函数终止进程;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>type tproinfo=record<br>filename:string;<br>proid:dword;<br>end;proinfo=^tproinfo;//自定义记录用来记录进程的文件名和ID;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; curr:tlist;<br>&nbsp; temp,b,a1:integer;<br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.processlist(var prolist: tlist);<br>var p:proinfo;<br>&nbsp; &nbsp; ok:bool;<br>&nbsp; &nbsp; prolisthandle:thandle;<br>&nbsp; &nbsp; prostruct:tprocessentry32; &nbsp; &nbsp;//记录进程的数据结构;<br>begin<br>prolist:=tlist.Create ;<br>prolist.Clear ;<br>prolisthandle:=createtoolhelp32snapshot(th32cs_snapprocess,0);<br>prostruct.dwSize :=sizeof(prostruct);<br>ok:=process32first(prolisthandle,prostruct);//发现第一个进程;<br>while integer(ok)&lt;&gt;0 do<br>begin<br>new(p);<br>p.filename :=prostruct.szExeFile ;<br>p.proid :=prostruct.th32ProcessID ;<br>prolist.Add (p);<br>ok:=process32next(prolisthandle,prostruct);//发现下一个进程;<br>end;<br>end;<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>a:string;<br>f:textfile;<br>begin<br>listbox1.Clear;<br>listbox2.Clear;<br>if fileexists('D:/Program Files/text1.txt') then<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//该文件记录你所想禁止运行的程序的路径;<br>assignfile(f,'D:/Program Files/text1.txt');<br>reset(f);<br>while not eof(f) do<br>begin<br>readln(f,a);<br>a:=uppercase(a); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//转化成大写字母;<br>listbox2.Items.Add (a); &nbsp; &nbsp; &nbsp; //记录所有被禁止运行程序的路径;<br>end;<br>closefile(f)<br>end<br>else application.Terminate ;<br><br>end;<br><br><br>procedure Tform1.exitcode;<br>var h:thandle;<br>a:dword;<br>p:proinfo;<br><br>begin<br>begin<br>p:=curr.items; &nbsp; //指向禁止运行的进程的数据结构;<br>h:=openprocess(process_all_access,true,p.proid);<br>getexitcodeprocess(h,a); &nbsp; &nbsp; &nbsp;//得到进程退出代码;<br>terminateprocess(h,a) ; &nbsp;//终止进程<br>end;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var i:integer;<br>p:proinfo;<br>begin<br>listbox1.Clear ;<br>processlist(curr); &nbsp; &nbsp; &nbsp; &nbsp;//调用进程列举的函数;<br>for i:=0 to curr.Count-1 do<br>begin<br>new(p);<br>p:=curr.Items;<br>listbox1.Items.Add(p.filename); &nbsp; &nbsp;//记录所有的进程的路径;<br>end; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//listbox2是记录所有禁止运行的程序的路径;<br>for i:=0 to listbox2.Items.Count-1 do<br>if (listbox1.Items.IndexOf(listbox2.Items.Strings)&gt;=0) then<br>begin<br>b:=listbox1.Items.IndexOf(listbox2.Items.Strings);<br>exitcode;//调用终止进程的函数;<br>end;<br>end;<br>end.
 
鼠标移到左下方,单击“开始”,选择“关机”,“关闭计算机”,然后“确定”。<br>更简单保险的办法:拔电源线,彻底关闭所有进程。--这样做太。。。了吧。
 
最彻底的方法:按reset
 
灌水散讲的人太多了!
 
(运行此程序前请保存所有修改过的文件)<br>procedure TForm1.ButtonKillAllClick(Sender: TObject);<br>var<br>&nbsp; &nbsp; pTask : PTaskEntry;<br>&nbsp; &nbsp; Task : Bool;<br>&nbsp; &nbsp; ThisTask: THANDLE;<br>begin<br>&nbsp; &nbsp; GetMem (pTask, SizeOf (TTaskEntry));<br>&nbsp; &nbsp; pTask^.dwSize := SizeOf (TTaskEntry);<br>&nbsp; &nbsp; Task := TaskFirst (pTask);<br>&nbsp; &nbsp; while Task do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if pTask^.hInst = hInstance then<br>&nbsp; &nbsp; &nbsp; &nbsp; ThisTask := pTask^.hTask<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; TerminateApp (pTask^.hTask, NO_UAE_BOX);<br>&nbsp; &nbsp; &nbsp; &nbsp; Task := TaskNext (pTask);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; TerminateApp (ThisTask, NO_UAE_BOX);<br>end;
 
谢谢Rik兄,好复杂啊,我头晕~~~~~~
 
后退
顶部