BOOL OpenProcessToken( HANDLE ProcessHandle, // handle to process DWORD DesiredAccess, // desired access to process PHANDLE TokenHandle // pointer to handle of open access token ); //GetCurrentProcess() TOKEN_PRIVILEGES tp; HANDLE hToken; OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken ) LUID luid; LookupPrivilegeValue(MachineName, SE_SHUTDOWN_NAME, &luid) tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(TOKEN_PRIVILEGES),NULL, NULL ); //到这里,是取得权限/// ExitWindowsEx(EWX_POWEROFF,EWX_FORCE); |