【问题标题】:Pass a variable to a psexec powershell command in vbscript将变量传递给 vbscript 中的 psexec powershell 命令
【发布时间】:2014-01-21 17:18:50
【问题描述】:

我正在尝试将用户输入的计算机名称传递给 psexec 命令。我什么都试过了。我知道该命令有效,因为如果我通过手动输入计算机名称来运行文件是成功的。我需要将 strComputer 变量放入 \strComputer psexec 命令中。提前致谢。

Set objShell = CreateObject("Wscript.shell")

Dim strComputer

strComputer=InputBox("Run app on remote computer",,"Type name here & click OK")

objShell.run("powershell psexec.exe -i -s \\strComputer \\domain.com\folder\app.exe domain.com")

MsgBox("Scan complete")

【问题讨论】:

  • 你到底为什么要混合使用 Vbs Powershell 和 Cli 工具?
  • 我猜是因为我没有这方面的经验。在远程机器上执行 psexec 的最佳解决方案是什么?在添加 powershell 之前,我什至无法让 psexec 运行。

标签: powershell command-line vbscript psexec


【解决方案1】:

为什么不为此使用 PowerShell 脚本?

Contents of myscript.ps1
------------------------
$computerName = Read-Host "Enter name of remote computer"
psexec \\$computerName -i -s \\domain.com\folder\app.exe domain.com
"Scan complete"

【讨论】:

  • 谢谢@Keith。我试图运行它,但我认为 GP 不会允许它。我只是得到一些红色文本,PS 窗口消失了。出于某种原因,如果我使用原始帖子中的方式,它将运行。
  • @Kevin_A 这是登录脚本吗?此外,当您使用 powershell.exe 运行此程序时,您可能需要使用参数 -ExeuctionPolicy Unrestricted
  • 不,不是登录脚本。我只想手动运行我们在远程机器上使用的 LAN 监控应用程序。我可以像上面键入的那样运行它,只需输入实际的计算机名称而不是 \\computerName。我不明白。 Get-ExecutionPolicy 返回 Restricted,但我无法更改它。我阅读了technet.microsoft.com/en-us/library/ee176949.aspx 的页面并尝试更改策略,但不允许我更改 reg 密钥。我不明白它如何在 objShell.run() 方法中使用 powershell 命令运行。这没有意义。
  • 只是一个错误说在这个系统上禁用了脚本的执行,但是我可以通过.vbs文件运行powershell...
  • 在 VBS 文件中,从技术上讲,您并没有运行 PowerShell 脚本,即 .ps1 文件。即使执行策略设置为受限,用户仍然可以在 PowerShell 控制台中以交互方式执行命令。您的 VBS 脚本或多或少在该模式下运行。当您运行 Set-ExecutionPolicy RemoteSigned 时,请确保您是从提升/管理控制台运行的。
猜你喜欢
  • 1970-01-01
  • 2020-09-08
  • 2012-11-07
  • 2022-12-13
  • 2013-05-01
  • 2014-02-19
  • 2019-02-16
  • 2017-12-15
  • 2012-06-24
相关资源
最近更新 更多