Solved

Getting the current user information?

Posted on 2004-03-29
10
530 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

776 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