|
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
DWORD dwVersion;
//获取当前操作系统版本
dwVersion = ::GetVersion();
if( dwVersion < 0x80000000 )
{//Windows NT and later
//获取权限
::OpenProcessToken(::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
::LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid );
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, NULL, 0 );
::ExitWindwosEx(EWX_REBOOT|EWX_FORCE, 0 );
}
else
{
::ExitWindwosEx(EWX_REBOOT|EWX_FORCE, 0 );
} |
|