VC编程使计算机休眠

void CPage1::OnXiuMian()
{
if(MessageBox(“确实要休眠吗?”,”关机程序”,MB_YESNO|MB_DEFBUTTON2|MB_ICONQUESTION)==IDYES)
{
static HANDLE hToken;
static TOKEN_PRIVILEGES tp;
static LUID luid;
if(::OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&hToken))
{
::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
tp.PrivilegeCount=1;
tp.Privileges[0].Luid =luid;
tp.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(hToken,false,&tp,sizeof(TOKEN_PRIVILEGES),NULL,NULL);
}
::SetSystemPowerState(false,true);
}
}
转载请说明出处:http://blog.csdn.net/mycaibo


你可能感兴趣的:(编程,null,query,token)