Close computer

xiaoxiao2021-03-06  188

void ShutDown () {// determine the operating system version OSVERSIONINFO osVer; osVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); :: GetVersionEx (& osVer); // operating system win2000if (osVer.dwPlatformId == VER_PLATFORM_WIN32_NT) {// Get a token for this process.HANDLE hToken; TOKEN_PRIVILEGES tkp; (! OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & hToken)). if MessageBox ( "OpenProcessToken Error"); // Get the LUID for the shutdown privilege LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, & tkp.Privileges [0] .Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges [0] .Attributes = SE_PRIVILEGE_ENABLED;. // Get the shutdown privilege for this process AdjustTokenPrivileges (hToken, FALSE, & tkp , 0, (PTOKEN_PRIVILEGES) NULL, 0); // Can not test the return value of AdjustTokenPrivileges if (GetLastError () = ERROR_SUCCESS) MessageBox ( "AdjustTokenPrivileges Error");.! // Shut down the system and force all applications to close . if (! EXITWINDOWSEX (EWX_Poweroff | EWX_FORCE, 0)) MessageBox ("EXITWINDOWSEX ERROR");} // System for Win98ELSE IF (! EXITWINDOWSEX (EWX_SHUTDOWN | EWX_FORCE, 0)) MessageBox ("Shutdown Error");

转载请注明原文地址:https://www.9cbs.com/read-128307.html

New Post(0)