Solved

Checking User privs on Winnt 4.0

Posted on 1998-05-08
2
188 Views
Last Modified: 2010-04-10
I am using Visual C++ 5.0 and I need a way to check to see if a user has Admin Privs. This may be a simple question, but I haven't been able to find the answer. The solution must support Unicode and non-English versions of NT.
0
Comment
Question by:alphab
2 Comments
 
LVL 1

Expert Comment

by:Blondie050798
ID: 1175042
Well I think generally the way that you are meant to check/inforce security on NT is to use Impersonation rather than explicitly determining what a user can and cannot do.  In that way you can become the user, carry out the action, and if the user is not allowed to carry out that action, then it won't happen! :-)
0
 

Accepted Solution

by:
lbrucher earned 100 total points
ID: 1175043
Here is the code I use to check to see if a user has admin proviledges. Does not matter Unicode or non-English NT
Hope this helps.

bool HasAdminRights()
{
      HANDLE                                    hAccessToken;
      UCHAR                                    InfoBuffer[1024];
      PTOKEN_GROUPS                        ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
      DWORD                                    dwInfoBufferSize;
      PSID                                    psidAdmins;
      SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
      bool                                    isSuccess;

      
      
      if ( ! OpenProcessToken(GetCurrentProcess(),TOKEN_READ,&hAccessToken) )
            return(false);


      isSuccess = GetTokenInformation( hAccessToken, TokenGroups, InfoBuffer, 1024, &dwInfoBufferSize );

      CloseHandle( hAccessToken );

      if ( ! isSuccess )
            return(false);


      if ( ! AllocateAndInitializeSid( &siaNtAuthority, 2,
                  SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_ADMINS,                         0,0,0,0,0,0,
                   &psidAdmins ) )
      return(false);



    if ( ! IsValidSid(psidAdmins) )
        return(false);


      isSuccess = false;

      for( unsigned int ix = 0; ix < ptgGroups->GroupCount; ix++ )
      {
            if ( IsValidSid(ptgGroups->Groups[ix].Sid) )
            if ( EqualSid( psidAdmins, ptgGroups->Groups[ix].Sid ) )
                {
                      isSuccess = true;
                      break;
                }
      }

      FreeSid(psidAdmins);

      return(isSuccess);
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 51
TCP/IP Socket - connection close results in data lost 14 120
Getting IP address 8 71
C++ standard library based binary archive format 6 91
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now