在水母上看到的一段,不过这是采用直接关机的方法了,应该有个更容易更通用的方法吧,比如通过调用Shell命令或者Kernel32的函数?
-------------------------------------------------------------------------------------------------------
if((TRUE == g->bSysTimeShutDown)&&(st.wHour == g->SysTimeShutDown.wHour)
&&((st.wMinute == g->SysTimeShutDown.wMinute)))
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get version info to determine operation
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) == 0)
return false;
// Determine the platform
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
// Windows NT 3.51, Windows NT 4.0, Windows 2000,
// Windows XP, or Windows .NET Server
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
::ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF,0);
}