void __fastcall TForm1::BnOKClick(TObject *Sender)
{
OSVERSIONINFO ovi;
ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&ovi))
{
if(ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(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);
}
}
}
unsigned int m = EWX_SHUTDOWN;
if(RbPowerOff->Checked) //选择了关机
m|=EWX_POWEROFF;
else if(RbReboot->Checked) //选择了重新启动
m|=EWX_REBOOT;
else if(RbLogoff->Checked) //选择了注销
m|=EWX_LOGOFF;
ExitWindowsEx(m,0); //执行选择的命令
Close();
}
--------------------next---------------------
阅读(1185) | 评论(0) | 转发(0) |