众所周知,在9x下关机只要ExitWindows(0,0)就行了,可是在NT/2000下这个函数
的执行结果仅是注销而已,那么如何在NT/2000下实现关机呢?看看下面这个函数吧!
void ShutDown(void)
{
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
GetVersionEx(&osv);
if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
HANDLE hProcess,hToken;
TOKEN_PRIVILEGES Privileges;
LUID luid;
hProcess=GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
Privileges.PrivilegeCount=1;
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
Privileges.Privileges[0].Luid=luid;
Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
}
ExitWindowsEx(EWX_POWEROFF,0);
}
本文地址:http://com.8s8s.com/it/it3940.htm