views:

685

answers:

3

Hi,

im writing an application that downloads and installs addons for programs which needs to save the data to program files (for the programs in question). Now this works fine on xp and vista with uac disabled however it is failing on normal vista due to the virtual folders.

How would one get around this with out needing to request admin rights every time the app started?

P.s. Program is written in c++, vis 2005

Edit: File system virtual folders: http://www.codeproject.com/KB/vista-security/MakingAppsUACAware.aspx

+8  A: 

Only write to Program Files during installation. After that, write to the user folders.

You can elevate the apps privileges later, but you'll just be delaying the prompt. The whole point of UAC is to prevent random apps from writing to folders that require admin privileges. (ok, not the whole point, but a large portion of it.)

You could create a service with admin privileges and send commands to it to move the downloaded files into the desired target directories, but this opens up a user's system to being abused by other apps if you don't design it very carefully.

This article talks about getting apps to work nicely with UAC. Also, see this article here.

Eclipse
I cant, as i need to install addons for other programs in program files
Lodle
Can you store the addons in another directory that does not need admin rights?
Michael Burr
no has to be in the program files/[program name] dir
Lodle
+1  A: 

Microsoft recommended to me when I spoke to them to have to write a second application, which you manifest as requiring administrative privileges. You use this application to deploy your file from a safe location (such as the users programdata directory) to the program files directory (Note that if your DLL isn't signed then this is a massive security hole as a virus/malicious user could manipulate the file before your function call).

Your non administrative app can call this application which will trigger UAC. People who understand UAC won't care and happily will click your application. Those who hate it will have switched it off. The call to start the new process (which required admin privileges) will throw a win32 exception if the user cancels the UAC dialog so beware to catch that.

The problem in vista is that it tries to help you by virtualising your program files directory if you are not admin. By design there is NO way that you can write to the program files directory unless you're administrator.

Another option is to create all of your "updates" as MSI updates. That way the windows installer will trigger UAC for you and you could provide a logo for your software etc.

Option 3 is to use clickonce deployment which will allow you to automatically update your program without UAC but you live in a sandbox on the users system which may not work with your application's current design.

Spence
Do services differ from normal apps in regards to uac? Maybe it would be a better way to make a service that does the updating.
Lodle
A: 

I got around uac by making a windows service that does the work i need and only runs while the app is running.

Lodle