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;
beginResult := 0;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);FProcessEntry32.dwSize := SizeOf(FProcessEntry32);ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);while Integer(ContinueLoop) <> 0 dobeginif ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) thenResult := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);end;CloseHandle(FSnapshotHandle);end;以下为要改的。我老写不对。目的是对比出不要的程序并杀死。
procedure TForm1.Button41Click(Sender: TObject);
var
  i: Integer;
  j: STRING;
begin
begin
  for i := 0 to l.Count-1 do
  begin
    j:=pProcessInfo(l.Items[i]).ExeFile;
    begin
        begin
    if
     j <> 'KERNEL32.DLL' then
     begin
     if
     j <> 'msgsrv32.exe' then
      begin
      if
      j <> 'explorer.exe' then
       begin
       if
       j <> 'rundll32.exe' then
        begin
        if
        j <> 'internat.exe' then
         begin
         if
         j <> 'mprexe.exe' then
          begin
          if
          j <> 'mmtask.tsk' then
         begin
          KillTask(j);
          ListBox1.Items.Add(j);
        end;
       end;
       end;
       end;
       end;
       end;
       end;
 end;
 end;
end;
end;
    showmessage('ok');
end;
大家帮忙拉

解决方案 »

  1.   

    这么乱,不会吧,写程序写成这样,厉害
    pf
    你用一个列表搞个循环,用的着用这么多if 来判断吗
      

  2.   

    给你一点点的建议:
    不用这么多if吧?
    你把要杀的进程名写到一个List中,然后对比一下,
    if LixtBox1.Items.Indexof(pro_name) > 0 then
      KillIt(abc);
    这样代码就简洁一点了。
      

  3.   

    procedure TForm1.Button41Click(Sender: TObject);
    const
      ExceptStr = ',KERNEL32.DLL,msgsrv32.exe,explorer.exe,rundll32.exe,'+
         'internat.exe,mprexe.exe,mmtask.tsk,';
    var
      i: Integer;
      j: STRING;
    begin
      for i := 0 to l.Count-1 do
      begin
        j:=pProcessInfo(l.Items[i]).ExeFile;//最长只有11位,Windows2000下
        if Pos(','+j, ExceptStr) < 1 then
        begin
          KillTask(j);
          ListBox1.Items.Add(j);
        end;
      end;
      showmessage('ok');
    end;
      

  4.   

    procedure TForm1.Button41Click(Sender: TObject);
    const
      ExceptStr = ',KERNEL32.DLL,msgsrv32.exe,explorer.exe,rundll32.exe,'+
         'internat.exe,mprexe.exe,mmtask.tsk,';
    var
      i: Integer;
      j: STRING;
    begin
      for i := 0 to l.Count-1 do
      begin
        j:=ExtractFileName(pProcessInfo(l.Items[i]).ExeFile);//这样修改才能适应98和2000
        if Pos(','+j, ExceptStr) < 1 then
        begin
          KillTask(j);
          ListBox1.Items.Add(j);
        end;
      end;
      showmessage('ok');
    end;
      

  5.   

    谢谢大家的帮忙,特别感谢huojiehai(海天子) ,哈哈帮我找出了问题所在。
    j:=ExtractFileName(pProcessInfo(l.Items[i]).ExeFile);//这样修改才能适应98和2000
    就是这里写错了。