2016-12-04 43 views
1

我想運行此命令,它將在設備範圍內輸出WiFi網絡,並將所有網絡保存爲變量,所有我目前所知的是:我想從一個命令記錄控制檯輸出並將其保存爲vbs中的變量

Dim networks 
set oShell = createobject("wscript.shell") 
oShell.run "cmd.exe /C netsh wlan show profiles" 

但unfortunatley我需要記錄它的一些方法,但我不知道怎麼了,任何幫助將不勝感激

回答

0

你的問題是,.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) 
相關問題