主页:http://www.maxss.net
邮件:[email protected]
BOOL ExitWindowsEx(
UINT uFlags, // shutdown operation
DWORD dwReason // shutdown reason
);更详细的参数说明请参阅MSDN。
在Windows 98实现“注销/重启/关机”功能代码:
ExitWindowsEx(EWX_LOGOFF, 0); // 注销
ExitWindowsEx(EWX_REBOOT, 0); // 重启
ExitWindowsEx(EWX_SHUTDOWN, 0); // 关机
在Windows 2000实现“注销/重启/关机”功能代码:
HANDLE hToken; TOKEN_PRIVILEGES tkp; if (FForce) // Forces processes to terminate FFlag |= EWX_FORCE; // 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(FFlag, 0);
本文地址:http://com.8s8s.com/it/it1528.htm