• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

Problem with UAC when downloading a exe using WebClient

Hi,

I'm using this to download a application (exe) from the web:
webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri(downloadpath), file);

This works fine if UAC is disabled and also when UAC is enabled as long my application is not installed to the "Program Files".
If UAC is enabled and my app try to download an exe using the WebClient fiddler doesn't show any action that I try to download anything (so no error message for sure).
In case I download a zip archive anything works fine ...

Is there a workaround to let the WebClient download an exe also when UAC is enabled and the downloading app is installed to the "Program Files"?

Thanks

Andre
0
andre72
Asked:
andre72
1 Solution
 
rowansmithCommented:
You need to download the file to a location that the user has access too.  Such as the DOWNLOADS directory or the TEMP directory.

-Rowan
0
 
andre72Author Commented:
And why is it possible to download a zip archive but not an exe?
0
 
systanCommented:
try to adjust you virus realtime protection to permissive not aggressive.
0
 
systanCommented:
try to adjust your ANTI virus software realtime protection to permissive not aggressive.
0
 
nffvrxqgrcfqvvcCommented:
<< Is there a workaround to let the WebClient download an exe also when UAC is enabled and the downloading app is installed to the "Program Files"? >>
You can download the file but as already mentioned you don't have write access to Program Files location. This doesn't mean you can't still download a file to another directory that allows write access which was already mentioned in the first post by rowansmith. You're trying to "download" to your executable location which won't work if it's located in the Program Files directory unless you use one of these options.
1) Change the "download" location to a location that has write access which typically is Public Documents and can be shared by all users.
2) Use Com Elevation to request the administrative token. (This is the BEST option because it can run sections of code in a surrogate process with elevated permissions. The best part is your application still runs at the AsInvoker level.)
3) Create a seperate executable that is manifested with (RequireAdministrator)  adding the download code to this process and setup command line parameters to pass url,filename then from your main application shell the executable to elevate the process so it has permissions to write into Program Files.
4) Manifest your main application with RequireAdministrator (The worst option if your application doesn't always need administrative rights. This will ask the user to run your application elevated each time they open the application.)

 
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now