开发者

UAC status without reading the registry

开发者 https://www.devze.com 2022-12-15 02:32 出处:网络
There\'s a simple way to read the registry and get the UAC status from there. The only problem is that if you are not an administrator user or the UAC is ON then you can\'t read that particular key.

There's a simple way to read the registry and get the UAC status from there. The only problem is that if you are not an administrator user or the UAC is ON then you can't read that particular key.

Is there a way (API, etc) to get the UAC status accurately without having to read the registry?

Sample code is always appreciated. Thanks!

jess

EDIT: I'm starting a bounty. PLEASE PLEASE if you are going to answer do not tell me how I shouldn't care about the UAC status and that the code should be independent of the UAC and how micros开发者_如何转开发oft is so goody goody.


From the internets:

HANDLE tokenHandle; 
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle); 

DWORD tokenInformationBufferLength = 0; 
TOKEN_ELEVATION_TYPE tokenElevation;
GetTokenInformation(tokenHandle, TokenElevationType, &tokenElevation, sizeof(tokenElevation), &tokenInformationBufferLength); 


Ok, building the answer on what ssg/comments already said:

http://www.softblog.com/2008-02/vista-tools/

This checks both elevation and UAC status. First as

How can I detect if my process is running UAC-elevated or not?

already mentions, it will test the ElevationStatus. After that, it tries to start a subprocess with elevated status which will fail if standard user is logged in, determining the UAC status.

And no, it does not use the registry.


Not quite where you're looking, I suppose... but if the registry read returns an access failure on the key, that is actually the answer you're looking for -- UAC is enabled.


What I did to solve this problem, was if I had admin rights according to the API call I read the registry value (UAC provides false to admin rights check) and if I did not have admin rights I tried to make a new key in HKEY_LOCAL_MACHINE\Software. If that succeeded, UAC was on and I removed the key.


First off, you don't really want to seek out a way to "get around" the security features of the operating system. Even if you do find a solution that works right now, Microsoft can (and does) change these kinds of features with Windows Update and will break your app in the future. Fighting the security features is an uphill battle and it will be a continuous headache for you. While I would love to hear more of your questions on StackOverflow :) it is most likely not the path you want to go down.

That said, I think you are going about the issue wrong. If your manager doesn't want you to fix the problem, then your manager has accepted the problem. Just mark the whole application as "must run in administrator mode" and be done with it. The users will get a single warning at application start and then the app will run for them. Here's a link to show you how to set this option.

Of course, if you're users don't have admin rights to their own machine you are basically out of luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消