?
Solved

Checking User privs on Winnt 4.0

Posted on 1998-05-08
2
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

752 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