暴力关机代码演示。
//利用微软未公开的API来实现瞬速关机,不知是否有副作用或后遗症。//测试环境XP SP3
//编译工具Visual C++ 6.0
#include <windows.h>
const int SE_SHUTDOWN_PRIVILEGE = 0x13;
typedef int (__stdcall *PFN_RtlAdjustPrivilege)(INT, BOOL, BOOL, INT*);
typedef int (__stdcall *PFN_ZwShutdownSystem)(INT);
int main()
{
HMODULE hModule = LoadLibrary("ntdll.dll");
if(hModule == NULL) {
return -1;
}
PFN_RtlAdjustPrivilege pfnRtl = (PFN_RtlAdjustPrivilege)GetProcAddress(hModule, "RtlAdjustPrivilege");
PFN_ZwShutdownSystem pfnShutdown = (PFN_ZwShutdownSystem)GetProcAddress(hModule, "ZwShutdownSystem");
if( pfnRtl != NULL && pfnShutdown != NULL) {
int en = 0;
int iRet = pfnRtl(SE_SHUTDOWN_PRIVILEGE, TRUE, TRUE, &en);
if(iRet == 0x0c000007c)
iRet = pfnRtl(SE_SHUTDOWN_PRIVILEGE, TRUE, FALSE, &en);
const int SH_POWEROFF = 2;
nRet = pfnShutdown(SH_POWEROFF);
}
return 0;
}