UnauthorizedAccessException in Windows Vista

V

Vanessa

Hi all!

I developed a self updating application (Windows Forms). When there is a new
version, I have to copy it to the directory that it was previously installed.

If the application is installed in another directory outside "\Program
Files", it is working well.

The problem is that if the application is installed in "\Program
Files\Product", where I have an UnauthorizedAccessException when I start
copying the new version (I am using File.Copy()). Is there a way to copy
files to this directory?

Thank you,
Vanessa
 
N

Nicholas Paldino [.NET/C# MVP]

Vanessa,

Well, it is more than likely that your user that is copying the files
doesn't have access, since it is the program files directory. They have to
be given access, and even then, they probably have to validate the action
through UAC on Vista (unless it is disabled).

Basically, there is nothing you can (or should) do in code if your user
doesn't have rights. You basically should catch the error, and inform the
user that they don't have the appropriate permissions.
 
S

Stanimir Stoyanov

Hi Vanessa,

Nicholas is right. UAC is preventing your application from writing to such
folders. One thing you can do is to make your application download a small
program (an updater, downloads update, attempts copy) which has a UAC-aware
manifest. You will execute the program and because of the manifest users
with administrative access will be able to finish the update. Otherwise,
catch the exception.

You can read about the UAC Manifest and .NET code at
http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx

Best Regards,
Stanimir Stoyanov | www.stoyanoff.info
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top