Question

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);
Était-ce utile?

La solution

Does it really need admin privilege to reboot OS?

No it does not. Standard user has reboot rights.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top