Question

I am trying to update some files in my application. I am trying to download the file, rename the current file to (.old) and then rename the downloaded file to the original file name (.exe).

When I run it in XP, it works fine. In Windows7, it gives me an error saying that access is denied. If I run the app from my desktop shortcut and set the properties of the shortcut to run as administrator, it works but it also prompts me to run the app as an admin every time I run it. I'm already logged in as an admin, so I don't want to be prompted every time I run it.

Is there a way in my program to simply rename the file as an administrator?

This is my rename code:

Dim old_file_name As String = Now.TimeOfDay.TotalMilliseconds & ".old"
File.Move(Application.StartupPath & "\myprog.exe", Application.StartupPath _
   & "\" & old_file_name)
Was it helpful?

Solution

In My case I found that there is no good (quiet) way to perform an operation on Windows7 as an administrator without being prompted for elevated privileges. One option is to have the end user change their UAC settings so they don't get prompted and this is not a viable option. Another to is change my program manifest but that results in a prompt for admin privileges every time they run it, also not very desirable. Another is to simply change the shortcut properties to run as administrator, but again, that prompts for admin privileges every time you run it. So what I ended up with is simply letting my program run a the normal user and when they want to upgrade the program, they choose to perform the upgrade. The upgrade is handled by a separate program (which gets called from my main program) that does have its manifest changed to run as administrator, which will prompt the user for privileges. This way, they only get prompted when they want to run the upgrade program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top