When I run my App on Win7 (UAC is on) with user privilege. It can sucessfully reboot OS, So in this case, No Administrator privilege is required? Is there any official document to describe this? Any comments is appreciated.

    HANDLE hToken = NULL;
    LUID luid;
    BOOL bRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
    bRet = LookupPrivilegeValue(L"", SE_SHUTDOWN_NAME, &luid);
    TOKEN_PRIVILEGES tp;
    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    bRet = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, 0);

    bRet = ExitWindowsEx(EWX_REBOOT|EWX_FORCE, 0);
有帮助吗?

解决方案

Does it really need admin privilege to reboot OS?

No it does not. Standard user has reboot rights.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top