windows VBScript- 作为管理员单行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13060215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBScript- Single line as administrator
提问by Seth
Is it possible to use the shell.run command to run the specified program as an administrator?
是否可以使用shell.run命令以管理员身份运行指定程序?
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.
我的另一个选择是将脚本分开并以管理员身份运行,并在该脚本中包含需要以管理员身份运行的内容,然后调用另一个脚本来正常运行并运行该脚本。
回答by JohnLBevan
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)
(来源:http: //social.technet.microsoft.com/Forums/eu/ITCG/thread/310e57f9-2367-4293-9f97-53d0e077aacc)
(More Info: http://ss64.com/vb/shellexecute.html)
(更多信息:http: //ss64.com/vb/shellexecute.html)