Einzelnen Beitrag anzeigen

matrix68

Registriert seit: 29. Mai 2003
9 Beiträge
 
#1

prozess in Taskmanager beenden aber wie ?

  Alt 9. Jun 2003, 19:38
Hallo,

ich würde gerne mal wissen wie man Systemprozesse beenden kann ?
Prozesse wie "Spoolsv.exe" lassen sich nur mit der Maus schliesen.
Habe mich schon überall umgeschaut und keine lösung dazu gefunden.
Ich habe es mit diesen Beispiel code probiert:

Delphi-Quellcode:
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;



{ For Windows NT/2000/XP } 

procedure KillProcess(hWindowHandle: HWND);
var
  hprocessID: INTEGER;
  processHandle: THandle;
  DWResult: DWORD;
begin
  SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
    SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);

  if isWindow(hWindowHandle) then
  begin
    // PostMessage(hWindowHandle, WM_QUIT, 0, 0);

    { Get the process identifier for the window} 
    GetWindowThreadProcessID(hWindowHandle, @hprocessID);
    if hprocessID <> 0 then
    begin
      { Get the process handle } 
      processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
        False, hprocessID);
      if processHandle <> 0 then
      begin
        { Terminate the process } 
        TerminateProcess(processHandle, 0);
        CloseHandle(ProcessHandle);
      end;
    end;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
   KillTask('spoolsv.exe');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   KillProcess(FindWindow('spoolsv.exe',nil));
end;

end.
Es läuft ohne Fehlermeldung aber "spoolsv.exe" ist immer noch aktiv
in Taskmanager !!!.
Wenn ich andere Prozesse schliessen will,z.b die auf user laufen
geht ohne weiteres.
Kann mir jemand helfen ?

gruss

Matrix

[edit=Daniel B]Delphi-Tags eingefügt. MfG Daniel B.[/edit]
  Mit Zitat antworten Zitat