Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AdjustTokenPrivileges()

Posted on 2000-04-09
2
Medium Priority
?
299 Views
Last Modified: 2013-11-20
I need an Exmple of how to set SE_SHUTDOWN_NAME Privilege.
0
Comment
Question by:TelMic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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