c 2b 2b admin windows

Solutions on MaxInterview for c 2b 2b admin windows by the best coders in the world

showing results for - "c 2b 2b admin windows"
Paola
13 Jan 2017
1#include <windows.h>
2#include <stdio.h>
3#pragma comment(lib, "cmcfg32.lib")
4
5BOOL SetPrivilege(
6    HANDLE hToken,          // access token handle
7    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
8    BOOL bEnablePrivilege   // to enable or disable privilege
9    ) 
10{
11    TOKEN_PRIVILEGES tp;
12    LUID luid;
13
14    if ( !LookupPrivilegeValue( 
15            NULL,            // lookup privilege on local system
16            lpszPrivilege,   // privilege to lookup 
17            &luid ) )        // receives LUID of privilege
18    {
19        printf("LookupPrivilegeValue error: %u\n", GetLastError() ); 
20        return FALSE; 
21    }
22
23    tp.PrivilegeCount = 1;
24    tp.Privileges[0].Luid = luid;
25    if (bEnablePrivilege)
26        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
27    else
28        tp.Privileges[0].Attributes = 0;
29
30    // Enable the privilege or disable all privileges.
31
32    if ( !AdjustTokenPrivileges(
33           hToken, 
34           FALSE, 
35           &tp, 
36           sizeof(TOKEN_PRIVILEGES), 
37           (PTOKEN_PRIVILEGES) NULL, 
38           (PDWORD) NULL) )
39    { 
40          printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
41          return FALSE; 
42    } 
43
44    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
45
46    {
47          printf("The token does not have the specified privilege. \n");
48          return FALSE;
49    } 
50
51    return TRUE;
52}
53
54
queries leading to this page
c 2b 2b admin wndowsc 2b 2b admin windows