Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




At first, may be somebody knows some easy way to know, am I privileged user or not? Until now I tryed to write to certain registry key in HKEY_LOCAL_MACHINE, in case of success I decided I am an admin. Now, in Vista, it does not work - Vista allows for everybody to write to system area of registry - to virtual registry file. I have found API IsUserAnAdmin(), but it does work only in Vista. Then I have found an example with CheckTokenMembership(). The API is present in mingw libraries I got recently, in libadvapi32.lib, the actual name of the entry is
There is no definition of it in mingw headers, so I define it locally as
extern BOOL WINAPI CheckTokenMembership(HANDLE, PSID, PBOOL);
Compiler generates such a reference to the different external name:
How to force compiler not to generate these additional pre/suffixes? Other API calls are compiled without any suffixes, for example,
compiles to

Compiler mingw GNU GCC 3.4.4, got together with Code::Blocks v1.0 rc2 IDE, OS Windows Vista.

Any ideas?
Thank you.

RE: IsUserAnAdmin?

You have to tell the compiler not to use C++ name decoration. Unforunately I don't know gcc.

In MS VC++ you should write :

extern "C" BOOL ... etc;
instead of
extern BOOL ... etc;

So give that a try.


RE: IsUserAnAdmin?

IsUserAnAdmin() is available in Win2K, WinXP and Vista.

RE: IsUserAnAdmin?


Quote (avanderlaan):

IsUserAnAdmin() is available in Win2K, WinXP and Vista.

It should be according to msdn specifications. Unfortunatelly, neither VC 6.0, nor Watcom, nor Mingw libraries do not contain such enter point. Is that probably a macro definition?

I found it under different name - IsUserAdmin(), undocumented though.

RE: IsUserAnAdmin?

IsUserAdmin if an example code from the MSDN CheckTokenMembership article:


BOOL IsUserAdmin(VOID)

Routine Description: This routine returns TRUE if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyone and is expected to be able to open its own process and process token.
Arguments: None.
Return Value:
   TRUE - Caller has Administrators local group.
   FALSE - Caller does not have Administrators local group. --
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
    0, 0, 0, 0, 0, 0,
    if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
         b = FALSE;

Get Windows SDK if you have not it in VC++ 6.0 old installation.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close