Solved

Checking User privs on Winnt 4.0

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

707 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