1。 把当前运行的程序名字都读书并记录下来。
2。 进行对比筛选,找出非平时所用的。(平时用的大于2个)小弟只有20分了。不够多,请大家多多包涵。

解决方案 »

  1.   


    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, TLHelp32, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        ListBox1: TListBox;
        ListBox2: TListBox;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      l : Tlist; ////返回的东东在"L"这个TList中。
    type
      TProcessInfo = Record
        ExeFile : String;
        ProcessID : DWORD;
      end;
      pProcessInfo = ^TProcessInfo;
      
    implementation{$R *.dfm}
    function EnableDebugPrivilege: Boolean;
      function EnablePrivilege(hToken: Cardinal; PrivName: string; bEnable: Boolean): Boolean;
      var
        TP: TOKEN_PRIVILEGES;
        Dummy: Cardinal;
      begin
        TP.PrivilegeCount := 1;
        LookupPrivilegeValue(nil, pchar(PrivName), TP.Privileges[0].Luid);
        if bEnable then
          TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
        else TP.Privileges[0].Attributes := 0;
        AdjustTokenPrivileges(hToken, False, TP, SizeOf(TP), nil, Dummy);
        Result := GetLastError = ERROR_SUCCESS;
      end;
    var
      hToken: Cardinal;
    begin
      OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken);
      if EnablePrivilege(hToken, 'SeDebugPrivilege', True) then ShowMessage('OK');
        CloseHandle(hToken);
    end;function KillTask(ExeFileName: string): Integer;
    const
      PROCESS_TERMINATE = $0001;
    var
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      Result := 0;
      FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
      ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
      while Integer(ContinueLoop) <> 0 do
      begin
        if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
        UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
        UpperCase(ExeFileName))) then
          Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));
        ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
      end;
      CloseHandle(FSnapshotHandle);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      p : pProcessInfo;
      i : integer;
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      l := TList.Create;
      l.Clear;
      FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
      ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
      while integer(ContinueLoop)<>0 do
      begin
        New(p);
        p.ExeFile := FProcessEntry32.szExeFile;
        p.ProcessID := FProcessEntry32.th32ProcessID;
        l.Add(p);
        ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 0 to l.Count-1 do
      begin
        ListBox1.Items.Add(pProcessInfo(l.Items[i]).ExeFile);
        ListBox2.Items.Add(IntToStr(pProcessInfo(l.Items[i]).ProcessID));
      end;
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 0 to l.Count-1 do
      begin
        ListBox1.Items.Add(pProcessInfo(l.Items[i]).ExeFile);
        begin
        if
        pProcessInfo(l.Items[i]).ExeFile='QQ.exe' then
        button2.Caption:=pProcessInfo(l.Items[i]).ExeFile;
        KillTask(button2.Caption);
        end;
        ListBox2.Items.Add(IntToStr(pProcessInfo(l.Items[i]).ProcessID));
      end;
    end;end.呵呵。解决。这给你分