views:

468

answers:

3

Similar to: http://stackoverflow.com/questions/17533/request-vista-uac-elevation-if-path-is-protected#17544

I have a .NET Client Application installed in c:\Program Files (Windows Vista). This application should update itself, but it doesn't because of permission issues. The auto-updater should simply replace a couple of assemblies, but they are all located under c:\Program File and the application throws the following exception:

System.UnauthorizedAccessException: Access to the path 'C:\Program Files...' is denied.

I have no control on where the application could be installed and the permission. Is there any workaround for this? Is it possible to request the Administrator rights for a couple of seconds? Is it possible to pop a UAC window? I am pretty sure that there a workaround... Otherwise, how Firefox would be able to update itself?

Thanks in advance for the help and ideas!

+1  A: 

You can't elevate a process's permissions halfway through, but you can start up another separate process with higher permissions that can do the work for you.

Get your main application to put all the files / installation details into a low-permission temporary location. When you're ready, start up a smaller application whose only job is to copy over those files to the Program Files directory (and maybe restart your main application with the new updates). Mark that application as requiring the needed permission to copy to the Program Files directory or write to the registry (or whatever else is needed).

Eclipse
+4  A: 

Could you use a Click Once deployment method? We use this for an internal application and users have no problems with permissions when we publish a new version. They are prompted to install the update when they launch the app (if a new version exists) and it installs without a hitch.

Richard West
This is a good idea, but I can't since it is an application integrated to Outlook.
Martin
Why to mark this as an answer then? :)
FractalizeR