windows 在脚本中以管理员身份运行 cmd.exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11459419/
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
run cmd.exe as administrator in a script
提问by Robert
I have a script that I need to run as Administrator just as I would right click on cmd.exe and click Run As Administrator.
我有一个脚本,我需要以管理员身份运行,就像我右键单击 cmd.exe 并单击以管理员身份运行一样。
Currently this is what I have:
目前这是我所拥有的:
Call WSHShell.Run("cmd.exe /K netdom renamecomputer ... end code")
回答by Jon Swanson
Have you tried using ShellExecute?
您是否尝试过使用 ShellExecute?
RunCmdElevated.vbs
运行CmdElevated.vbs
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cmd.exe", "/k echo test", "", "runas", 1
wscript RunCmdElevated.vbs
wscript RunCmdElevated.vbs
gives
给
test
C:\Windows\system32>
测试
C:\Windows\system32>
in a new window. The "1" is the view mode
在新窗口中。“1”是查看模式