VBScript- Single line as administrator

限于喜欢 提交于 2019-12-06 12:04:06

问题


Is it possible to use the shell.run command to run the specified program as an administrator?

for instance:

shell.run(cmd.exe) <---Run this as admin
shell.run(Notepad) <---Run this as normal

I know i can execute the script to run as admin but that means everything inside that script is executed as an administrator.

My other option was to seperate the scripts and run one as admin and include what needs to be ran as admin in that script, then call another script to run and run that one as normal.


回答1:


Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "cmd.exe", , , "runas", 1
oShell.Run "nodepad.exe"

(Source: http://social.technet.microsoft.com/Forums/eu/ITCG/thread/310e57f9-2367-4293-9f97-53d0e077aacc)

(More Info: http://ss64.com/vb/shellexecute.html)




回答2:


Windows (from XP through to Win7 at least) has a runas command which does what you need. See here for details.

So, instead of running cmd.exe, you would run runas.exe, giving cmd.exe as the program to run.



来源:https://stackoverflow.com/questions/13060215/vbscript-single-line-as-administrator

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