Listing Account Privileges

Last reviewed: September 25, 1995
Article ID: Q119669
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1 and 3.5
    

SUMMARY

When a user starts a process, that process takes on the security attributes of the user. The security attributes inherited from the user include privileges, which control access to system services.

MORE INFORMATION

To list the privileges belonging to a process (and thus to the current user), perform the following steps:

  1. Call GetCurrentProcess() to obtain a handle to the current process.

  2. Call GetProcessToken() to obtain the process' access token.

  3. Call GetTokenInformation() to obtain the list of privileges (among other information).

  4. Step through the list of privileges, using LookupPrivilegeName() and LookupPrivilegeDisplayName() to obtain the names for the program to display.

The following sample code lists the displayable privilege names and the privilege names as defined in the WINNT.H header file:

Sample Code

   #include <windows.h>
   #include <stdio.h>

   void main()
   {
      HANDLE hProcess, hAccessToken;
      UCHAR InfoBuffer[1000];
      PTOKEN_PRIVILEGES ptgPrivileges = (PTOKEN_PRIVILEGES)InfoBuffer;
      DWORD dwInfoBufferSize;
      DWORD dwPrivilegeNameSize;
      DWORD dwDisplayNameSize;
      UCHAR ucPrivilegeName[500];
      UCHAR ucDisplayName[500];
      DWORD dwLangId;
      UINT x;

      hProcess = GetCurrentProcess();

      OpenProcessToken( hProcess, TOKEN_READ, &hAccessToken );

      GetTokenInformation( hAccessToken, TokenPrivileges, InfoBuffer,
         sizeof(InfoBuffer), &dwInfoBufferSize);

      printf( "Account privileges: \n\n" );
      for( x=0; x<ptgPrivileges->PrivilegeCount; x++ )
      {
         dwPrivilegeNameSize = sizeof( ucPrivilegeName );
         dwDisplayNameSize = sizeof( ucDisplayName );
         LookupPrivilegeName( NULL, &ptgPrivileges->Privileges[x].Luid,
            ucPrivilegeName, &dwPrivilegeNameSize );
         LookupPrivilegeDisplayName( NULL, ucPrivilegeName,
            ucDisplayName, &dwDisplayNameSize, &dwLangId );
         printf( "%40s (%s)\n", ucDisplayName, ucPrivilegeName );
      }
   }


Additional reference words: 3.10 3.50
KBCategory: kbprg
KBSubcategory: BseSecurity


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 25, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.