问题
Is there a way for an app to present the user with the UAC prompt only once, upon first running. Thereafter, no further prompting.
In other words, I understand that our app needs the user's UAC permission to do certain things. And that's fine. But we don't want it to have to keep asking on every occasion it runs. Can the user give permission to our app for all time? Or does what I am asking violate the fundamentals of UAC?
We are working with .NET and Windows 7
回答1:
The answer to your question is: No, you cannot do that.
Microsoft specifically is forbidding such behavior. If a applications could add themselves to an exclude list, then we get back into the mess we had before.
What you need to do is make your program not require administrative access.
Ask yourself: What did you do on Windows XP?
- am i not allowed to run your software?
- does your software crash when i'm a standard user?
- does your software provide no value, and have no absolutely no functionality when run by a standard user?
Windows XP doesn't have the convince of the UAC. The only way for a user to run your program as an administrator is to logon with another user. And that's a much worse user experience than clicking "Continue".
If you don't want to write software that is standard user friendly, then you're part of the problem. UAC is not the problem, UAC is a convience. i can turn off UAC, run as a standard user full time, and your software still won't work.
Microsoft considered
- white-lists
- Remember my preference
- Don't ask me again.
If you had a white-list, then every program would just add itself to such a list at install time.
If such a white-list existed, then your app would be the target of malware. It would love to modify the binary to execute what it wants; since it knows the program will be silently elevated.
Malware would love to poke at your application with SendMessage, trying to pass invalid data or structures, trying to get your, administrative, application to execute the code it wants.
If the user had the option to disable future prompts on programs, then they would just do it, and every program would run as an administrator, and we'll be back to the way things were.
All those ideas don't solve the problem: almost no program actually requires administrative access.
The time has finally come to force developers to come to terms with that fact.
Whitelists cannot work
Some people want to come up with ways to make whitelists work.
Have a checkbox where the user can say, "Don't prompt me for this file anymore"
If you store that filename, then other programs with the same name will silently run as administrators.Okay, then we'll record the full path, or use the hash of the file, as the whitelist entry. If there's a whitelist then other programs will add themselves to that list when they install, and have programs running with administrative access that the user didn't want.
What if only signed applications are allowed, that way we know they're safe. Applications are not safe because they're signed. An application doesn't have to be malware for it to be abused into doing bad things. (e.g. buffer overruns in flash, firefox, ie, chrome, safari, opera, word, photoshop, Yahoo image uploader tool).
You have to store list of valid code-signers in a list somehwere. And no matter how you slice it, having any white-list will mean that applications will just add themselves to that list.
- Well, then don't allow them access to the list. Not even administrators are allowed to add items to the list. If not even administrators can add items to the list, then how can the user add items to the list in the first place? You can't add items to the whitelist if you're not allowed to add items to the whitelist!
And how do you manage the white-list? Lets say the user has changed their mind, or Dad has changed his mind, or IT has changed its mind, or corporate has changed its mind, or the software publisher changes their mind: how do you remove items from the list - especially when nobody is allowd to modify the list.
Summary: White lists cannot work.
回答2:
The only way is to install yourself as a service or device driver.
回答3:
Update: Oops I originally misread the question and interpreted it as "prompt only once, on the very first run" instead of "only once every, every time it's run" (edited accordingly below).
You can't grant an application Administrator rights for all time, that does indeed go against the design of UAC.
However, one way around this is to create a service which your app communicates with, which is able to run in the background and perform tasks with elevated permissions without the main application needing elevated permissions.
A service will only need to prompt once, when it is installed.
If that sounds like too much work, you could have a look at bundling with the SkipUAC utility which uses an approach like this to allow users to start applications without being prompted for UAC on each startup.
My Original Answer:
If the executable has a manifest with requireAdministrator set it should trigger a UAC prompt only on each initial startup, but not after that (i.e. all operations, including other apps launched by the initial process will inherit the elevated permissions, but if you quit the application and start it again the prompt will once again appear).
You can set up a manifest for an EXE via the IDE in Visual Studio 2008/2010, or using a command line utility that comes with the most recent service pack for VS 2005 (this can be integrated into the build step to automate the process, but is a bit of a fudge in 2005).
I would search the web for "UAC" and "manifest" for more information, it's reasonably well documented in the online MSDN documentation (once know you to look for it).
This works equally in Windows 7 and Windows Vista.
回答4:
This may be of help:
http://www.tipandtrick.net/2008/bypass-or-disable-uac-for-selected-excluded-programs-only-with-elevator-skipuac/
回答5:
If this is possible (I dont think it is considering say How to configure Visual Studio not to give UAC prompt on each run?), I'm pretty sure it has to be done on the users side (like disabling the prompt in the first place), rather than the application side.
回答6:
Developers need a slap in the back of the head do they???
I have created 2 backup programs.
Both require Admin Rights to run.... why? So the user can backup there files where ever they are of course..
Could i run this as a service in the background? mabye? Probably not.
This is the reason that all AV software for instance has services in the background. So the GUI is just the GUI that is it... has no functionallity except to pass the command/info back to the service at which point the commands etc get run.
Wether or not whitelists would work depends on the users... I know users who for a fact just click on 'ALLOW' all the time... they dont even read it. So how is UAC protecting them, remarks like there stupid etc dont help. They do this because UAC prompts them everytime they go to do something.
Backup Programs, Launching apps, Compilers, generators ALL these things for example need admin rights.
Quite frankly a service is not always the answer as it is time consuming to implement and you can't be sure that it gets removed/restarted (auto updating) when it needs to be.
回答7:
The user should be able to right-click on the executable and go to properties -> compatibility -> "run this program as administrator’"
来源:https://stackoverflow.com/questions/2019743/can-we-get-the-uac-prompt-to-show-only-once