当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

使用当前进程关闭系统的实现方法

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);

相关内容
赞助商链接