Access token privilege attributes

This is a discussion on Access token privilege attributes within the Windows Programming forums, part of the Platform Specific Boards category; I have a program that lists all of the privileges of a certain access token and their attributes. However, a ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Access token privilege attributes

    I have a program that lists all of the privileges of a certain access token and their attributes. However, a number of privileges don't have any attributes associated with them. Does this mean they are not enabled? And if so why? I am the administrator of my computer.

    Some of them are these:
    SeSecurityPrivilege
    SeBackupPrivilege
    SeShutdownPrivilege
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    id id
    Guest
    One must specifically enable them for the process:

    Code:
    Usage: SetProcessPrivilege(SE_SHUTDOWN_NAME);
    
    BOOL SetProcessPrivilege(LPCTSTR lpPrivilege) {
    
    	/* This function enables a privilege for the current process */
    	/* lpPrivilege can be either a privilege constant eg. SE_SHUTDOWN_NAME
    	 * which is DEFINEd in the windows headers to the string 
    	 * "SeShutdownPrivilege" or the string can be used directly. */
    
    	TOKEN_PRIVILEGES tp;
    	HANDLE hToken;
    	LUID luid;
    	OSVERSIONINFO osvi;
    
    
    	/* Check that we are a Win NT system before proceeding */
    	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    	GetVersionEx (&osvi);
    	if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
    	{
    		PRINTF("Error: System is not NT based");
    		return FALSE;
    	}
    
    
    	/* Get the local id of our desired privilege */
    	if ( !LookupPrivilegeValue( 
    		NULL,               // lookup privilege on local system
    		lpPrivilege,        // privilege to lookup 
    		&luid ) )           // receives LUID of privilege
    	{
    		PRINTF("LookupPrivilegeValue error: %u\n", GetLastError() ); 
    		return FALSE; 
    	}
    
    
    	/* Fill in TOKEN_PRIVILEGES structure */
    	tp.PrivilegeCount = 1;
    	tp.Privileges[0].Luid = luid;   // the luid of the privilege to enable
    	tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    
    
    	/* Get the access token for the current process */
    	if ( !OpenProcessToken(
    		GetCurrentProcess(),
    		TOKEN_ADJUST_PRIVILEGES,
    		&hToken ) )
    	{
    		PRINTF("OpenProcessToken error: %u\n", GetLastError() ); 
    		return FALSE; 
    	}
    
    
    	/* Enable the privilege */
    	if ( !AdjustTokenPrivileges(
    	       hToken,         // access token
    	       FALSE,          // don't disable all privileges
    	       &tp,            // TOKEN_PRIVILEGES struct
    	       sizeof(TOKEN_PRIVILEGES), 
    	       (PTOKEN_PRIVILEGES) NULL, 
    	       (PDWORD) NULL) )
    	{ 
    		PRINTF("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
    		CloseHandle(hToken);
    		return FALSE; 
    	} 
    
    
    	/* Close the process access token */
    	CloseHandle(hToken);
    
    
    	return TRUE; //success
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Parsing and Tokens (strtok)
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 04-22-2002, 10:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21