CMD.exe 与 cscript/wscript

发布于 2024-11-10 06:17:03 字数 910 浏览 4 评论 0原文

所以我尝试通过嵌入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯叶蝶 2024-11-17 06:17:03

尝试引用您的密码:

cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1  "contoso\administrator" 'Pa$w0rd' /dlv

Cmd 不会将 $ 解释为任何特殊内容。然而,Powershell 认为您有一个名为 $w0rd 的变量,并且可能正在替换一个空字符串。单引号将阻止尝试替换;双引号不会。

Trying quoting your password:

cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1  "contoso\administrator" 'Pa$w0rd' /dlv

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文