Realization of shutdown in 2000 and NT

zhaozj2021-02-11  221

I just learned Vc soon, once a friend asked me to make a software for him, he is a network management, I want to go home in advance every day, but the machine can't stop in advance, I want to work for him to shut down the software, I am pleased, remember to see Over an article, close the computer, just use an API function, so I get it three times. Give your friends, the next day, my friends hurriedly found it, saying that I have compiled it, failing. I think it is impossible, so I took carefully, not right, I have to use it on the machine. Carefully check MSDN, notice that NT and 2000 machines have a note on the NT and 2000 after the parameter EWX_SHUTDOWN, so take carefully, oh, it is necessary to shut down in NT or 2000 must first get off. Hurry and ask your friends to get the machine, it is the 2000 operating system. Re-transformation, wow, I didn't expect that this privilege for the 2000 operating system is still more cumbersome, and the code is given and some explanations, huh, huh. You can define a child process.

BOOL MyExitWindowsEx (UINT uFlag) {OSVERSIONINFO osv; // define an operating system information structure osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO; GetVersionEx (& osv); // current operating system query if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) // Analyzing Is it 2000 / NT {

// The following is to acquire permission operation to the operating system Handle HProcess, HToken; Token_Privieges Privileges; Luid Luid; HProcess = getCurrentProcess ();

// the following to open the current process of dialogue OpenProcessToken (hProcess, TOKEN_ADJUST_PRIVILEGES, & hToken); Privileges.PrivilegeCount = 1; LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, & luid); Privileges.Privileges [0] .Luid = luid; Privileges.Privileges [0]. Attributes = SE_PRIVILEGE_ENABED; AdjustTokenPrivileges (HToken, False, & Privileges, NULL, NULL, NULL); EXITWINDOWSEX (UFLAG, 0);}

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

New Post(0)