Run as admin?

darxide

Member
Joined
Mar 30, 2012
Messages
9
Programming Experience
1-3
I've got a working program written up that downloads a file from a site and unzips it to a specific location. Everything works fine when I test the program, but once I compile it and try to run it I get timeout errors at the My.Computer.Network.DownloadFile line. The site I'm downloading from has a counter which only allows you to download the data file 10 times per 24 hours and even with the timeout error the counter is incrementing on my user control panel but the file does not download.

If I run the program as administrator it works just fine. Is there a way to get the program to always run as admin, or at the very least pop up the UAC window to prompt as the program is executed? Having to right-click-> run as admin every time is frustrating and I'd like it to be a lot cleaner when I release the program for distribution. I've got a feeling this is just a firewall restriction, but I don't know if it's even possible to have my program automatically create it's own exception. That seems like it would defeat the entire purpose of a firewall.

Edit: I figured out how to prompt the user at launch. Is there another way to allow this program to run without prompting? Some way I can rewrite it to allow the download without requireing admin privleges? I know I have programs that I run every day that use internet access and sometimes download files but don't prompt for me to allow them privileges every time I run them.
 
Last edited:
I've got a working program written up that downloads a file from a site and unzips it to a specific location. Everything works fine when I test the program, but once I compile it and try to run it I get timeout errors at the My.Computer.Network.DownloadFile line. The site I'm downloading from has a counter which only allows you to download the data file 10 times per 24 hours and even with the timeout error the counter is incrementing on my user control panel but the file does not download.

If I run the program as administrator it works just fine. Is there a way to get the program to always run as admin, or at the very least pop up the UAC window to prompt as the program is executed? Having to right-click-> run as admin every time is frustrating and I'd like it to be a lot cleaner when I release the program for distribution. I've got a feeling this is just a firewall restriction, but I don't know if it's even possible to have my program automatically create it's own exception. That seems like it would defeat the entire purpose of a firewall.

Edit: I figured out how to prompt the user at launch. Is there another way to allow this program to run without prompting? Some way I can rewrite it to allow the download without requireing admin privleges? I know I have programs that I run every day that use internet access and sometimes download files but don't prompt for me to allow them privileges every time I run them.

I have never had to do anything like this before so don't realy know what to do but I have something that might be of interest to you. Check out this address Making a .NET app run on Vista with Administrator priviledges - .NET sample code - developer Fusion It looks like this might be what you need.

Regards
 
Downloading doesn't require admin rights, but the path you are trying to save to may do. Use a path the non-admin user has write rights to.
 
Downloading doesn't require admin rights, but the path you are trying to save to may do. Use a path the non-admin user has write rights to.

I'm saving to the temp directory with System.IO.Path.GetTempPath

The temp directory should be open to non-admins, right? If so, then why does the program fail to download unless I run it with admin privileges?
 
GetTempPath returns the current users temp path, where it has write permissions. Neither that or Network.DownloadFile requires admin rights from .Net point of view. Perhaps there is a firewall blocking internet access for your app for the regular user?
 
Yea, that's what I did. It prompts the user at launch to allow access to the program. This works, but I was hoping to eliminate that step entirely.

This maybe a stupid question but in the Manifest File did you set the level to highestAvailable which should according to MSDN Microsoft allow the application to run without any fuss. Unless I am reading this wrong.

Regards
 
This maybe a stupid question but in the Manifest File did you set the level to highestAvailable which should according to MSDN Microsoft allow the application to run without any fuss. Unless I am reading this wrong.
article said:
Now, whenever your application starts it will always trigger UAC and ask the user to allow administrator access for your program.
Unless user explicitly starts a process as administrator, a program requesting this level will always ask user.
 
Right now it's set to requireAdminister. This way it prompts when started which at least works as a band-aid fix for now.

When run with asInvoker, this is what I get:

VB.NET:
************** Exception Text **************
System.Net.WebException: The operation has timed out
   at System.Net.WebClient.DownloadFile(Uri address, String fileName)
   at Microsoft.VisualBasic.MyServices.Internal.WebClientCopy.DownloadFile(Uri address, String destinationFileName)
   at Microsoft.VisualBasic.Devices.Network.DownloadFile(Uri address, String destinationFileName, ICredentials networkCredentials, Boolean showUI, Int32 connectionTimeout, Boolean overwrite, UICancelOption onUserCancel)
   at Microsoft.VisualBasic.Devices.Network.DownloadFile(String address, String destinationFileName, String userName, String password, Boolean showUI, Int32 connectionTimeout, Boolean overwrite, UICancelOption onUserCancel)
   at TUJDownloader.frmMain.DoWork() in C:\Users\Nobody\documents\visual studio 2010\Projects\TUJ Downloader 2\TUJ Downloader 2\frmMain.vb:line 36
   at TUJDownloader.frmMain.Form1_Load(Object sender, EventArgs e) in C:\Users\Nobody\documents\visual studio 2010\Projects\TUJ Downloader 2\TUJ Downloader 2\frmMain.vb:line 17
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

But as stated earlier, the request is sent for download as my counter increments by 1 on the site's user page even though no file is ever downloaded.

Using highestAvailable DOES seem to work the way I want it. There's no UAC prompt at all, there's no error. The program works as expected. My only concern is that I am the sole user of my computer and therefore my account has admin access. Would this work this way on a non-admin account? Would there be a prompt or an error? I can live with a prompt for non-admin users.
 
Last edited:
Would this work this way on a non-admin account?
Adding a new user account to your system can be done in a few seconds, then you can try it out. I also do have a restricted user account for testing, which I used to verify my previous statements in this thread.
 
Back
Top