简体   繁体   中英

VB.NET - Run shell without UAC?

We are using "hobocopy" to run backups of PST files.

The problem is that when hobocopy is ran, it pops up with a "User Access Control" dialog asking for permission to run.

I am using "Shell" in VB.net to run the hobocopy, but it needs to run in the background and quietly.

Is there a way to run the "Shell" command with admin privileges so it won't ask permission?

My understanding is that your application is launching hobocopy from code that you've written.

If you want to do this without any UAC prompt, then you have two options:

  • disable UAC (not recommended!)
  • launch your application with elevated permissions (ie "Run as administrator")

In a typical situation I'd not recommend either of these, but if you have to run hobocopy then (from the description of the app) I'd imagine there is no UAC-free option.

One other thing you could try is to right-click the application or shortcut in Windows, select "Properties," and enable the "Run as administrator" option in that dialogue. Depending on the exact permissions requested by the application, this might avoid UAC prompts. (For example: it works for Task Manager, but not for Regedit; I don't have Hobocopy to test.)

Why use Shell alltogether?

Try using

System.Diagnostics.Process
System.Diagnostics.ProcessStartInfo

it gives you more possibilities, such as to not run it in the shell, or to execute a programm in a specific context (such as another user)

Edit: As Dan point's out this does not solve the UAC problem, so here some more thoughts

After searching the Net for solutions, i quickly noticed that there are ways to defeat UAC, but those are Hacks . So if you need to defeat UAC for a smooth HMI there is most likley a design error.

Ways to solve this problem may include:

  • Executing hobocopy as Administrator (need to enable Administrator account)
  • -> Eigther the way Dan described, or by using ProcessStartInfo.User
  • Disabeling UAC
  • Hacking your way into an elevated permission state
  • Running the programm or an auxiliary process as a service , interfacing with it via ServiceControl

Only the latter of which seems to me as a legitimate solution, but would require to redesign your app. Executing a piece of backup software on event or schedule seems to me like something a service should do anyways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM