提示某个进程正在阻止电脑关闭,应该是那个进程截取了WM_QUERYENDSESSION消息,我用此方法在XP SP3中测试没成功过,论坛中有这样的一个例子。
以下这段代码,删除explorer.exe进程令牌中的SeShutdownPrivilege特权,阻止通过explorer关机、重启或待机。在XP SP3中测试成功,在WIN7中应该也可以。
#include <Thread.au3>
#include <lsasecur.au3>
Local $hThread, $hToken, $hRestrictToken, $hDupToken, $aPriv[1] = [$SE_SHUTDOWN_PRIV]
_RTGetWindowThreadProcessId(WinGetHandle("[class:Shell_TrayWnd]"))
$hThread = _SeOpenThread(@extended, $SE_THREAD_SET_THREAD_TOKEN)
If $hThread < 1 Then
MsgBox(48, "Error", _SeFormatMsg())
Exit
EndIf
$hToken = _SeOpenProcessToken(-1)
$hRestrictToken = _SeCreateRestrictedToken($hToken, 0, 0, $aPriv, 0)
$hDupToken = _SeDuplicateTokenEx($hRestrictToken, $SE_TOKEN_IMPERSONATION)
If _SeSetThreadToken($hThread, $hDupToken) Then
MsgBox(48, "OK", _SeFormatMsg("", 0))
Else
MsgBox(48, "Error", _SeFormatMsg())
EndIf
_SeCloseHandle($hDupToken)
_SeCloseHandle($hRestrictToken)
_SeCloseHandle($hToken)
_SeCloseHandle($hThread)
|