怎么检查某个程序是否在进程里啊,比如qq.exe。

解决方案 »

  1.   

    下面是引用大富翁的代码:uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,tlhelp32,stdCtrls, ExtCtrls;//注意加上tlhelp32这个单元;
    type     
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Timer1: TTimer;
        ListBox2: TListBox;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        private
      procedure processlist(var prolist:tlist);//自定义函数列举所有的进程;
      procedure exitcode ;//自定义函数终止进程;
        { Private declarations }
      public
        { Public declarations }
      end;
    type tproinfo=record
    filename:string;
    proid:dword;
    end;proinfo=^tproinfo;//自定义记录用来记录进程的文件名和ID;var
      Form1: TForm1;
      curr:tlist;
      temp,b,a1:integer;
    implementation{$R *.DFM}
    procedure TForm1.processlist(var prolist: tlist);
    var p:proinfo;
        ok:bool;
        prolisthandle:thandle;
        prostruct:tprocessentry32;    //记录进程的数据结构;
    begin
    prolist:=tlist.Create ;
    prolist.Clear ;
    prolisthandle:=createtoolhelp32snapshot(th32cs_snapprocess,0);
    prostruct.dwSize :=sizeof(prostruct);
    ok:=process32first(prolisthandle,prostruct);//发现第一个进程;
    while integer(ok)<>0 do
    begin
    new(p);
    p.filename :=prostruct.szExeFile ;
    p.proid :=prostruct.th32ProcessID ;
    prolist.Add (p);
    ok:=process32next(prolisthandle,prostruct);//发现下一个进程;
    end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    var
    a:string;
    f:textfile;
    begin
    listbox1.Clear;
    listbox2.Clear;
    if fileexists('D:\Program Files\text1.txt') then
    begin                //该文件记录你所想禁止运行的程序的路径;
    assignfile(f,'D:\Program Files\text1.txt');
    reset(f);
    while not eof(f) do
    begin
    readln(f,a);
    a:=uppercase(a);          //转化成大写字母;
    listbox2.Items.Add (a);       //记录所有被禁止运行程序的路径;
    end;
    closefile(f)
    end
    else application.Terminate ;end;
    procedure Tform1.exitcode;
    var h:thandle;
    a:dword;
    p:proinfo;begin
    begin
    p:=curr.items[b];   //指向禁止运行的进程的数据结构;
    h:=openprocess(process_all_access,true,p.proid);
    getexitcodeprocess(h,a);      //得到进程退出代码;
    terminateprocess(h,a) ;  //终止进程
    end;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    var i:integer;
    p:proinfo;
    begin
    listbox1.Clear ;
    processlist(curr);        //调用进程列举的函数;
    for i:=0 to curr.Count-1 do
    begin
    new(p);
    p:=curr.Items[i];
    listbox1.Items.Add(p.filename);    //记录所有的进程的路径;
    end;                //listbox2是记录所有禁止运行的程序的路径;
    for i:=0 to listbox2.Items.Count-1 do
    if (listbox1.Items.IndexOf(listbox2.Items.Strings[i])>=0) then
    begin
    b:=listbox1.Items.IndexOf(listbox2.Items.Strings[i]);
    exitcode;//调用终止进程的函数;
    end;
    end;
    end.