-1

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);
Jerry YY Rain
  • 4,134
  • 7
  • 35
  • 52
  • 1
    What exactly is your question? Does your code work? If not, what's not working? Are you getting an error? If your code works, are you asking us "Why does this work like I wrote it to work?"? I have no idea what you're asking us here. – Ken White Sep 06 '13 at 03:19
  • I mean it works. As I think this action should need Administrator privilege, however, as above code, with normal user privilege, it can also work. So, UAC is be passed? – Jerry YY Rain Sep 06 '13 at 03:22
  • 1
    It doesn't take Administrator privileges to reboot or shutdown the machine - if it did, a normal user wouldn't be able to reboot or shutdown properly and could only yank the power cord out. – Jonathan Potter Sep 06 '13 at 03:36

1 Answers1

1

Does it really need admin privilege to reboot OS?

No it does not. Standard user has reboot rights.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490