CMD.exe 与 cscript/wscript
所以我尝试通过嵌入 powershell 脚本中的 cscript.exe 运行 VBscript。它不断因权限错误而出错。在调试代码时,我意识到确切的命令不会在 cscript 或 wscript 中运行,而是从命令提示符运行。我的印象是,默认情况下 cmd.exe 调用 wscript 来执行 VBScript。
这是让我失望的代码。
$hostname = MIA-DC1
$user = contoso\administrator
$password = Pa$$w0rd
cscript.exe c:\windows\system32\slmgr.vbs $hostname $user $password /dlv
我首先认为是变量搞砸了,但是,以下所有操作都失败并出现相同的错误:
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$$w0rd /dlv
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$$w0rd /dlv
但是,如果我在命令提示符中键入命令(以任何形式),它会按预期运行,不会提出任何问题。
我现在有点没有主意了。有人可能会指出 cmd.exe 调用 cscript/wscript 与我自己调用之间的区别吗?
预先非常感谢。
So I am trying to run a VBscript via cscript.exe embedded within a powershell script. It keeps erroring out with a permissioning error. While debugging the code, I realized that the exact command will not run in cscript or wscript, but will run from the command prompt. I was under the impression that by default cmd.exe calls wscript to execute VBScript.
this is the code that's failing me.
$hostname = MIA-DC1
$user = contoso\administrator
$password = Pa$w0rd
cscript.exe c:\windows\system32\slmgr.vbs $hostname $user $password /dlv
I first thought it was the variables that were screwing it up however, all of the following have failed with the same error:
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$w0rd /dlv
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$w0rd /dlv
However, should I type the command (in any form) into a command prompt, it runs as intended no questions asked.
I'm a bit out of ideas at this point. could someone possibly point me to differences between cmd.exe calling cscript/wscript versus calling it myself?
Thanks so much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试引用您的密码:
Cmd 不会将 $ 解释为任何特殊内容。然而,Powershell 认为您有一个名为 $w0rd 的变量,并且可能正在替换一个空字符串。单引号将阻止尝试替换;双引号不会。
Trying quoting your password:
Cmd doesn't interpret a $ as anything special. Powershell, however, thinks you have a variable named $w0rd and is probably substituting an empty string. Single quotes will prevent the attempted substitution; double quotes will not.