Solved

AdjustTokenPrivileges()

Posted on 2000-04-09
2
279 Views
Last Modified: 2013-11-20
I need an Exmple of how to set SE_SHUTDOWN_NAME Privilege.
0
Comment
Question by:TelMic
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 2698387
0
 
LVL 32

Expert Comment

by:jhance
ID: 2698389
           HANDLE hToken;
            TOKEN_PRIVILEGES tkp;
            char szBuf[100];

        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
            wsprintf(szBuf, "OpenProcessToken Error #%d", GetLastError ());
            AfxMessageBox(szBuf, MB_OK);
                  EndDialog(IDC_REBOOT);
        }

        // Get the LUID for shutdown privilege
        if(!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid)){
            AfxMessageBox("LookupPrivilegeValue() FAILED", MB_OK);
                  EndDialog(IDC_REBOOT);
        }
        else{
            tkp.PrivilegeCount = 1;  // one privilege to set
            tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        }

            // Get shutdown privilege for this process.
        if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, NULL, NULL, NULL)){
            wsprintf(szBuf, "AdjustTokenPrivileges Error #%d", GetLastError ());
            AfxMessageBox(szBuf, MB_OK);
                  EndDialog(IDC_REBOOT);
        }

        if(GetLastError() != ERROR_SUCCESS){
            wsprintf(szBuf, "AdjustTokenPrivileges() failed for reason %d", GetLastError());
            AfxMessageBox(szBuf, MB_OK);
                  EndDialog(IDC_REBOOT);
        }
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now