VBScript 变量为空

问题描述 投票:0回答:0

我正在尝试在 VBScript 变量中捕获机器的 DNS 服务器地址。这将在 .hta 文件中使用。

我目前的代码如下。它返回如下所示的错误。行参考是紧跟在脚本最后一行之后的行。

我怀疑这意味着变量

strPSResults
是空的,但我不确定我哪里出错了。在 Powershell 中运行,该命令在两行中为我提供了两个 IPv4 地址。

当我得到这个排序时,我将尝试将 Powershell 的两行输出分成两个单独的变量,但那是另一天的事。

一如既往,非常感谢您提供的任何建议和帮助。

' --------------------------------------------------------------------------------'
' CAPTURE DNS PROVIDER IPs INTO VBSCRIPT VARIABLE
' --------------------------------------------------------------------------------'

Option Explicit
Dim strPSCommand
Dim strDOSCommand
Dim objShell
Dim objExec
Dim strPSResults

Dim WScript

' --- Construct PowerShell Command (PS syntax)
strPSCommand = "Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object –ExpandProperty ServerAddresses"

' --- Consruct DOS command to pass PowerShell command (DOS syntax)
strDOSCommand = "powershell -command " & strPSCommand & ""

' --- Create shell object
Set objShell = CreateObject("Wscript.Shell")

' --- Execute the combined command
    Set objExec = objShell.Exec(strDOSCommand)

' --- Read output into VBS variable
strPSResults = objExec.StdOut.ReadAll

' --- Echo results
WScript.Echo(strPSResults)
powershell variables vbscript hta
© www.soinside.com 2019 - 2024. All rights reserved.