Win95 and Win2000 shutdown and restart

zhaozj2021-02-16  31

Void shutdownprocess (void) // shutdown program {

if (IsWindows9x ()) {ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, 0);} else {HANDLE hToken; TOKEN_PRIVILEGES tkp; if (! OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & hToken)) {MessageBox (NULL, "not shutdown" , CLASSNAME, MB_OK); return;} LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, & tkp.Privileges [0] .Luid); tkp.PrivilegeCount = 1; tkp.Privileges [0] .Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges (hToken, FALSE, & tkp, 0, (ptoken_privileges) null, 0); if (getLastError ()! = Error_success) {MessageBox (NULL, "Unable to shut down", classname, mb_ok);} if (! EXITWINDOWSEX (EWX_SHUTDOWN | EWX_FORCE, 0)) {MessageBox NULL, "Unable to shut down", classname, mb_ok;}}}

Void RebootProcess (Void) // Restart Program {

if (IsWindows9x ()) {ExitWindowsEx (EWX_REBOOT | EWX_FORCE, 0);} else {HANDLE hToken; TOKEN_PRIVILEGES tkp; if (! OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & hToken)) {MessageBox (NULL, "not shutdown" , CLASSNAME, MB_OK); return;} LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, & tkp.Privileges [0] .Luid); tkp.PrivilegeCount = 1; tkp.Privileges [0] .Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges (hToken, FALSE, & tkp, 0, (ptoken_privileges) null, 0); if (getLastError ()! = Error_success) {MessageBox (NULL, "Unable to shut down", classname, mb_ok);} if (! EXITWINDOWSEX (EWX_REBOOT | EWX_FORCE, 0)) {MessageBox NULL, "Unable to shut down", classname, mb_ok;}}}

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

New Post(0)