Solved

Getting the current user information?

Posted on 2004-03-29
10
529 Views
Last Modified: 2013-11-20
hi guys,
In my application,i need to enabling or disabling the controls based on the user privilege .ie if the user is an administrator some of the option is visible otherwise it has to be hide.

So whether there is an possiblity for checking the useris an administrator,poweruser or guest etc...
Thx in advance
Regards
vjayaprasen

 
0
Comment
Question by:vjayaprasen
  • 5
  • 4
10 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 125 total points
ID: 10702549
BOOL IsUserAdmin(VOID)
{
      BOOL b;
      SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
      PSID AdministratorsGroup;

      b = AllocateAndInitializeSid(&NtAuthority,
                                                 2,
                                                 SECURITY_BUILTIN_DOMAIN_RID,
                                                 DOMAIN_ALIAS_RID_ADMINS,
                                                 0, 0, 0, 0, 0, 0,
                                                 &AdministratorsGroup);
      if( b )
      {
            if ( !CheckTokenMembership( NULL, AdministratorsGroup, &b) )
            {
                   b = FALSE;
            }

            FreeSid(AdministratorsGroup);
      }

      return(b);
}
0
 

Author Comment

by:vjayaprasen
ID: 10703142
hi roshman,
i got a error message like
CheckTokenMembership undeclared identifier..
i also try it for including advapi32.lib .
i am using MFC dialog based application
thx
regards
vijayaprasen
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10703264
including "Advapi32.lib" will work...

Project->Settings=>Link

type "Advapi32.lib" in the Object Modules text box

Rosh :)
0
 

Author Comment

by:vjayaprasen
ID: 10703500
i already inluded that .lib ..
but it doesnt seems to work
:-(
regards
prakash
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10703523
Plz copy/paste the error text here
0
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.

 

Author Comment

by:vjayaprasen
ID: 10703530
error C2065: 'CheckTokenMembership' : undeclared identifier
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10703558
I think u hav to install platform sdk 2000
0
 

Author Comment

by:vjayaprasen
ID: 10703748
mine PC have already platform sdk 2000 installed
:-(
vjayaprasen
0
 
LVL 3

Expert Comment

by:akalmani
ID: 10704459
Did you include the header file

#include <winbase.h>

I see no other reason why it should not work.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10710395
put this in your stdafx.h

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

22 Experts available now in Live!

Get 1:1 Help Now