tags:

views:

1148

answers:

4

I want to get the process's user name and check if it is a local administrator . Or check directly if the current procees user is a local administrator

+3  A: 

http://vcfaq.mvps.org/sdk/21.htm

How To Determine Whether a Thread Is Running in User Context of Local Administrator Account

These links might help [for Windows].

aJ
helpful links but very long is there no shorter and easier way to get the user's name once I have the user's name I can check if it's in the desired local administrator group
sofr
If you just want to get the username, you can use WINAPI GetUserName ==> http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx
aJ
A: 

C++ has no notion of 'administrator'. Any solution would be via a platform specific library. What platform are you using?

Visage
A: 

Presuming you're on a Window OS there's a shell function: IsUserAnAdmin

See MSDN article

This article does suggest rolling your own function though, use CheckTokenMembership. There is even a code example to help you along.

MrBry
thanks! but all I got is the logged on user I'M looking for a way to get the user wjo runs a service and check if it is a local administrator
sofr
I'm not sure where you are coming from. But I'm willing to help. Some more background on what you're ultimately trying to achieve may help me.Is this service something you have written? If so you can apply security during installation to allow/deny users (and/or groups) to start or stop the service, if this is what you are after?Generally windows services are not run as the user that started them. By default the system account is used as the account a service is run under but this can be configured to be any user you wish. The service threads may then impersonate users as they wish.
MrBry
+1  A: 

Get the current username with GetUserName(), then call NetUserGetInfo() with the server name (NULL for local) and username you just got. Pass it a USER_INFO_1 structure, and then access usri1_priv in the structure. If the value is USER_PRIV_ADMIN, then you'll know that the username is an admin.

ZZZzzz