Solved

Problem with UAC when downloading a exe using WebClient

Posted on 2010-09-23
5
838 Views
Last Modified: 2013-12-16
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
Comment
Question by:andre72
5 Comments
 
LVL 11

Expert Comment

by:rowansmith
ID: 33742688
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
 

Author Comment

by:andre72
ID: 33751954
And why is it possible to download a zip archive but not an exe?
0
 
LVL 14

Expert Comment

by:systan
ID: 33759804
try to adjust you virus realtime protection to permissive not aggressive.
0
 
LVL 14

Expert Comment

by:systan
ID: 33759807
try to adjust your ANTI virus software realtime protection to permissive not aggressive.
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 33769602
<< 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Lee
Windows 7 Ultimate and Enterprise (and 2008 R2) introduced a new feature you may not be aware of - Boot from VHD.   Boot from VHD (or what Microsoft refers to asNative Boot allows you to install Windows to a VHD (Virtual Hard Disk) file that is t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question