Solved

Checking User privs on Winnt 4.0

Posted on 1998-05-08
2
189 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 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