2,641
社区成员
发帖
与我相关
我的任务
分享
static HANDLE hToken;
static TOKEN_PRIVILEGES tp;
static LUID luid;
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);
LookupPrivilegeValue(NULL,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,0); //关机
ExitWindowsEx(EWX_REBOOT,0); //重启