user3146967
user3146967

Reputation: 23

How to have vbs launch a program as administrator?

The end of my VBScript (the rest is mainly WScript.Echo reminders) looks like this (launches X-Plane, maximized):

Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""X:\X-Plane\X-Plane.exe"""), 3
Set objShell = Nothing

What would I need to add to this to get X-Plane to run as administrator? An hour's Googling has got me nowhere!

Upvotes: 1

Views: 7139

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200543

Provided you have UAC enabled and your user is a member of the Administrators group you can use the ShellExecute method with the "runas" verb:

Set app = CreateObject("Shell.Application")
app.ShellExecute "X:\X-Plane\X-Plane.exe", , , "runas", 3

Upvotes: 1

Related Questions