Vbscript 我想记录命令的控制台输出,并将其保存为vbs中的变量
我想运行此命令,该命令将输出设备范围内的WiFi网络,并将所有网络保存为一个变量,到目前为止我所知道的是:Vbscript 我想记录命令的控制台输出,并将其保存为vbs中的变量,vbscript,Vbscript,我想运行此命令,该命令将输出设备范围内的WiFi网络,并将所有网络保存为一个变量,到目前为止我所知道的是: Dim networks set oShell = createobject("wscript.shell") oShell.run "cmd.exe /C netsh wlan show profiles" 但不幸的是,我需要一些方法来记录它,但我不知道如何记录,任何帮助都将不胜感激您的问题是.Run方法无法访问已执行程序的输出。您需要使用Exec方法,并从StdOut属性检索程序的输
Dim networks
set oShell = createobject("wscript.shell")
oShell.run "cmd.exe /C netsh wlan show profiles"
但不幸的是,我需要一些方法来记录它,但我不知道如何记录,任何帮助都将不胜感激您的问题是
.Run
方法无法访问已执行程序的输出。您需要使用Exec
方法,并从StdOut
属性检索程序的输出
Option Explicit
Dim shell, executed, buffer
rem Instantiate the needed component to launch another executable
Set shell = WScript.CreateObject("WScript.Shell")
rem If you expect a lot of data from the output of the command
rem or if you need separate lines
Set executed = shell.Exec("netsh wlan show profiles")
Do While Not executed.StdOut.AtEndOfStream
buffer = executed.StdOut.ReadLine()
Call WScript.Echo( buffer )
Loop
rem For short outputs, you can retrieve all the data in one call
Set executed = shell.Exec("netsh wlan show profiles")
buffer = executed.StdOut.ReadAll()
Call WScript.Echo( buffer )