"c++ admin windows" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ admin windows" answered properly. Developers are finding an appropriate answer about c++ admin windows related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ admin windows. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ admin windows. 

c++ admin windows

By JulesG10JulesG10 on May 28, 2021
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "cmcfg32.lib")

BOOL SetPrivilege(
    HANDLE hToken,          // access token handle
    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
    BOOL bEnablePrivilege   // to enable or disable privilege
    ) 
{
    TOKEN_PRIVILEGES tp;
    LUID luid;

    if ( !LookupPrivilegeValue( 
            NULL,            // lookup privilege on local system
            lpszPrivilege,   // privilege to lookup 
            &luid ) )        // receives LUID of privilege
    {
        printf("LookupPrivilegeValue error: %u\n", GetLastError() ); 
        return FALSE; 
    }

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    if (bEnablePrivilege)
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    else
        tp.Privileges[0].Attributes = 0;

    // Enable the privilege or disable all privileges.

    if ( !AdjustTokenPrivileges(
           hToken, 
           FALSE, 
           &tp, 
           sizeof(TOKEN_PRIVILEGES), 
           (PTOKEN_PRIVILEGES) NULL, 
           (PDWORD) NULL) )
    { 
          printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
          return FALSE; 
    } 

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)

    {
          printf("The token does not have the specified privilege. \n");
          return FALSE;
    } 

    return TRUE;
}

Source: docs.microsoft.com

Add Comment

0

All those coders who are working on the C++ based application and are stuck on c++ admin windows can get a collection of related answers to their query. Programmers need to enter their query on c++ admin windows related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ admin windows for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ admin windows while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ admin windows". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ admin windows resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "c++ admin windows"

View All C++ queries

C++ queries related to "c++ admin windows"

Browse Other Code Languages

CodeProZone