簡體   English   中英

如何永久終止Windows資源管理器(“explorer.exe”進程)?

[英]How to permanently terminate Windows Explorer (the “explorer.exe” process)?

我正在使用以下代碼來終止進程:

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;

問題是,當我調用上面的函數以永久終止explorer.exe ,Windows資源管理器會終止,但之后會重新啟動:

KillTask('explorer.exe');

我正在使用Delphi XE3,Delphi 7和Windows 8。

基於這個Exit Explorer功能和Luke在this post調試的代碼,您可以嘗試使用以下代碼:

警告:

這種方式絕對沒有記載! 因此,這篇文章中出現的所有常量和變量都是虛構的。 任何與真實的,有文件記錄的代碼的相似之處純屬巧合:-)

function ExitExplorer: Boolean;
var
  TrayHandle: HWND;
const
  WM_EXITEXPLORER = $5B4;
begin
  Result := False;
  TrayHandle := FindWindow('Shell_TrayWnd', nil);
  if TrayHandle <> 0 then
    Result := PostMessage(TrayHandle, WM_EXITEXPLORER, 0, 0);
end;

我已經在Windows 7中測試了它,它可以工作,甚至不需要管理員提升。 不知道其他系統怎么樣(我說這至少在Windows XP上不起作用,但這只是猜測)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM