Solved

Checking User privs on Winnt 4.0

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

717 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