1

I have barely started vbs so I am new. I need help trying to show all wifi networks available around me. I am trying to fit it all in one msgBox. Here is my code so far.

Set objShell = CreateObject("Wscript.Shell")
strCommand = "netsh wlan show network mode=bssid "
Set objExecObject = objShell.Exec(strCommand)

Do While Not objExecObject.StdOut.AtEndOfStream
    strText = objExecObject.StdOut.ReadAll()
Loop

 
Wscript.Echo strText

It works fine for me just I can't see all the wifi names in one msgbox. It gets cut in the middle. Also, please make sure the script is in vbscript. It can not be make in HTA. Can anybody help me? Thank you!

coder9927
  • 180
  • 12
  • 1
    I'd write the results to a text file. – Rno Nov 08 '20 at 23:02
  • Does this answer your question? [VBScript - Capturing output from stdout](https://stackoverflow.com/questions/32920690/vbscript-capturing-output-from-stdout) – user692942 Nov 17 '20 at 11:26
  • @Lankymart Thank you for your help but I don't want a hta. I need a vbs. Thank you, – coder9927 Nov 17 '20 at 14:38
  • Does this answer your question? [Trying to redirect stdout to a file](https://stackoverflow.com/a/18728464) – user692942 Nov 17 '20 at 14:58
  • I am sorry but it still doesn't. I appreciate your effort, though. – coder9927 Nov 17 '20 at 15:00
  • Does this answer your question? [How can I redirect my vbscript output to a file using batch file?](https://stackoverflow.com/a/32496816) – user692942 Nov 17 '20 at 15:00
  • 1
    If you are already capturing the output from `StdOut` and echoing out on the script just using a command line `> myfile.txt` should create and add the content of `StdOut` to the file. If this isn't what you are asking then please, explain what's different. – user692942 Nov 17 '20 at 15:03
  • Thank you and this helps, thanks to your explanation. I am sorry but I have just started scripting few weeks ago. – coder9927 Nov 17 '20 at 15:06
  • @coder9927 If that is the case, how can you be certain that the duplicate doesn't answer your question? Basically, your script requires no alteration what so ever, you just call it from a batch file or the command line using the `> myfile.txt` to create and output the `StdOut` to the `myfile.txt` (or whatever you want to name it). – user692942 Nov 17 '20 at 15:06
  • 1
    Because at first, I didn't know how to use it. But thanks to your explanation, the code got to my nugget. – coder9927 Nov 17 '20 at 15:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224693/discussion-between-coder9927-and-lankymart). – coder9927 Nov 17 '20 at 20:08

1 Answers1

2

You can do something like that save the data results into text file instead of MsgBox :

Set objShell = CreateObject("Wscript.Shell")
strCommand = "cmd /c netsh wlan show network mode=bssid>%Appdata%\BSSID.txt & start /MAX Notepad %Appdata%\BSSID.txt"
objShell.Run strCommand,0,True

EDIT : 09/11/2020

You can give a try for this vbscript :

Const ForReading = 1
Set objShell = CreateObject("Wscript.Shell")
strCommand = "cmd /c netsh wlan show network mode=bssid>%Appdata%\BSSID.txt"
objShell.Run strCommand,0,True
ResultFile = objShell.ExpandEnvironmentStrings("%Appdata%\BSSID.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(ResultFile, ForReading)
strText  = ObjFile.ReadAll
arrLines = Split(strText,vbCrlf)

Set oReg = New RegExp
With oReg
    .Global = True
    .Pattern = "\r\n" 'vbCrLf
    lCount = .Execute(strText).Count + 1
End With

'WScript.Echo lCount

For i = 4 to lCount/2 + 2
    M1 = M1 + arrLines(i) & vbcrlf
Next
    
For i = lCount/2 + 2 to lCount - 1
    M2 = M2 + arrLines(i) & vbcrlf
Next

wscript.echo M1
wscript.echo M2
Hackoo
  • 18,337
  • 3
  • 40
  • 70