How to have vbs launch a program as administrator?

ぃ、小莉子 提交于 2021-01-28 05:42:42

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/46267758/how-to-have-vbs-launch-a-program-as-administrator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!