如何永久终止Windows资源管理器(“ explorer.exe”进程)? [英] How to permanently terminate Windows Explorer (the "explorer.exe" process)?

查看:235
本文介绍了如何永久终止Windows资源管理器(“ explorer.exe”进程)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码终止进程:

I'm using the following code to terminate a 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资源管理器会终止,但随后会重新启动:

The problem is, when I call the above function in order to permanently terminate the explorer.exe, the Windows Explorer terminates though, but it's re-started afterwards:

KillTask('explorer.exe');

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

I'm using Delphi XE3, Delphi 7 and Windows 8.

推荐答案

基于此 退出浏览器 功能和代码由卢克在 此帖子 您可以尝试使用以下代码:

Based on this Exit Explorer feature and code debugged by Luke in this post you may try to use the following code:

警告:

Warning:

这种方式绝对没有记载!因此,本文中出现的所有常量和变量都是虚构的。与真实的,记录的代码的任何相似之处纯属巧合:-)

This way is absolutely undocumented! So all constants and variables appearing in this post are fictitious. Any resemblance to real, documented code is purely coincidental :-)

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上无法使用,但这只是一个猜测)。

I've tested it in Windows 7, where it works and doesn't even need the administrator elevation. Don't know how about the other systems (I'd say this won't work at least on Windows XP, but it's just a guess).

这篇关于如何永久终止Windows资源管理器(“ explorer.exe”进程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆