views:

57

answers:

2

I'm creating a Windows app that automatically updates itself. I'm not using ClickOnce for a variety of reasons. When I try to File.Move() my updated files to C:\Program Files on Windows 7, I get the following error:

Access to the path 'C:\Program Files\<company>\<app>\<app.exe>' is denied.

I am not given a UAC prompt. The exe that I am trying to update is not currently running.

A: 

Your problem is UAC, even though you aren't getting a UAC prompt.

You need to change your program's manifest to automatically elevate. (This will give you a UAC prompt)

SLaks
Why was this downvoted?
SLaks
You should only run as admin if there actually is an update to apply.
SLaks
I created another exe with the proper manifest. When I have a new update to install, I call the other exe to copy the files. So the UAC prompt only appears when it needs to. Thanks.
Michael L Perry
+1  A: 

You can't make changes in the program's install folder, you don't have the required admin privileges. Adding a manifest to your updater isn't practical, the user is quickly going to tire seeing the elevation prompt.

The only practical way is to run your updater as a scheduled task. Those tasks are permitted to run with admin privileges because it requires admin privileges to schedule one. Which you'll need to do with your installer.

Hans Passant