阿杰 发表于 2011-1-8 15:20:05

VC 瞬间关机(使用RtlAdjustPrivilege和ZwShutdownSystem)

#include <windows.h>

const unsigned int SE_SHUTDOWN_PRIVILEGE = 0x13;

int main()
{
HMODULE hDll = ::LoadLibrary("ntdll.dll");
typedef int (* type_RtlAdjustPrivilege)(int, bool, bool, int*);
typedef int (* type_ZwShutdownSystem)(int);
type_RtlAdjustPrivilege RtlAdjustPrivilege = (type_RtlAdjustPrivilege)GetProcAddress(hDll, "RtlAdjustPrivilege");
type_ZwShutdownSystem ZwShutdownSystem = (type_ZwShutdownSystem)GetProcAddress(hDll, "ZwShutdownSystem");
int nEn = 0;
int nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, true, &nEn);
if(nResult == 0x0c000007c)
{
nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, false, &nEn);
}
nResult = ZwShutdownSystem(2);
FreeLibrary(hDll);
return 0;
}

364589886 发表于 2011-2-26 20:35:19

后面的freelibrary多余。。。

lxl1638 发表于 2011-2-27 01:51:06

本帖最后由 lxl1638 于 2011-2-27 19:45 编辑

要看ZwShutdownSystem的返回值,是否FreeLibrary
这样写是不错的,ZwShutdownSystem执行成功,系统就关闭,FreeLibrary就不被执行;
ZwShutdownSystem执行不成功,系统不能关闭,FreeLibrary就要执行。

Murray 发表于 2011-5-12 23:03:53

本帖最后由 Murray 于 2011-5-12 23:07 编辑

比ExitWindows方便多了。
.代码量要少很多阿代码copy下了

lgsnake 发表于 2012-2-10 17:00:36

呵呵,写的可以,哈哈

upring 发表于 2015-6-12 20:15:27

请问楼主 支持win7吗
页: [1]
查看完整版本: VC 瞬间关机(使用RtlAdjustPrivilege和ZwShutdownSystem)