gpt4 book ai didi

windows - 如何永久终止 Windows 资源管理器( "explorer.exe"进程)?

转载 作者:可可西里 更新时间:2023-11-01 14:42:01 25 4
gpt4 key购买 nike

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

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 上不起作用,但这只是一个猜测)。

关于windows - 如何永久终止 Windows 资源管理器( "explorer.exe"进程)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13770128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com