void CRebootDlg::OnCok()
{
// TODO: Add your control notification handler code here
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
DWORD dwVersion; //版本号
dwVersion = GetVersion(); //得到WINDOWS NT或Win32的版本号
switch(m_mark)//由接收单选项值进行相关操作
{
case 0:
ExitWindowsEx(EWX_LOGOFF,0);
break; //注消操作
case 1:
if(dwVersion < 0x80000000)
{
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,(PTOKEN_PRIVILEGES)NULL,0);
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);
}
else //WIN系列其它系统
{
ExitWindowsEx(EWX_FORCE | EWX_REBOOT,0);
}
break; //重启操作
case 2:
if(dwVersion < 0x80000000)//用于判断WIN系列,从而设置相应的权限
{
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,(PTOKEN_PRIVILEGES)NULL,0);
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);
}
else
{
ExitWindowsEx(EWX_FORCE | EWX_SHUTDOWN ,0);
}
break;//关闭计算机
}
}