Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

Earlier I attached a manifest file to my legacy program prompting UAC elevation on the start up of a program. While the UAC does prompt upon program start up, I am currently unable to get the section of my program requiring administrator status to properly output on computers separate from my own.

To properly debug this, I need to make sure that when I transfer this app to other computers, they are in fact also running my program with elevated administrator settings.

My question is this:
Is there a relatively simple way to, at run time, determine whether or not a program is running with elevated administrator settings?

If I can perform this check on another computer and it turns out that it is running with administrator status, I'll be able to confirm that the issue is with my code and not my method of prompting the UAC for elevation. I will also note that I am working with Windows 7.

Thanks for reading this! Let me know if anything is unclear about my request.
Posted
Updated 31-Oct-12 8:14am
v2

1 solution

The solution can be found there:
http://stackoverflow.com/questions/95912/how-can-i-detect-if-my-process-is-running-uac-elevated-or-not[^].

[EDIT]

This is not the same as checking IsUserAnAdmin:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776463%28v=vs.85%29.aspx[^].

This API merely checks up if the user is in the Administrator's group. This is not what you need: to get elevated privileges, the user does not have to be in this group, and the privileges can be denied (via UAC) is the user is a member of this group.

I think this API was only useful for OS before Vista and Windows Server 2008 when UAC was introduced. For more information, please see:
http://en.wikipedia.org/wiki/User_Account_Control[^].

[END EDIT]

However, if you properly devise your manifest, you don't really need to check it up. You can consider the functionality you need is already built in UAC in the following sense: if the user can get a requested privilege and confirm in the UAC confirmation dialog which appears automatically, the application will be executed, always with elevated privileges; in all other cases, if cannot be executed at all. I think if this functionality can be enough for your purpose, it's always better.

If do understand that in certain cases you really need to check up the elevation in the application code. One simple example is: if it is granted the elevated privileges, you show full set of operations, if not, you hide or, better, disable some items from its UI. I just don't see where you would need it in your case. You know better, of course.

—SA
 
Share this answer
 
v4
Comments
Parwarrior7 31-Oct-12 16:53pm    
Thanks again Sergey! I'll make sure to check all of this out tomorrow. I need to use it merely for a quick debugging exercise, just to make sure that the program is ACTUALLY doing what I think it's doing. Because if it is then I've been looking for my error in the wrong place for a few days now and need to refocus my efforts.
Sergey Alexandrovich Kryukov 31-Oct-12 17:10pm    
You are welcome.
And when and if you can see that it makes sense, please accept the answer formally (green button) -- thanks.
--SA
Parwarrior7 1-Nov-12 10:30am    
Do you have any idea what SDK I would need to have to compile that stack overflow C++ solution? I'm having some issues trying to compile it.
Sergey Alexandrovich Kryukov 1-Nov-12 10:39am    
On C++? Nothing, windows api, #include windows.h. Just Google on each API function name. For example:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa446671%28v=vs.85%29.aspx
--SA
Parwarrior7 1-Nov-12 10:44am    
Specifically it's just the one "__out TOKEN_ELEVATION_TYPE" declaration that's giving my compiler issues.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900