you can probably save the whole file creation and use the Exec command on the WScript.Shell object. It returns a WshScriptExec object with access to the StdOut and StdErr channels (ie. no need to redirect output). Take a look at the WScript help, there are a few examples on how to use it.
that big switch case is hurting my eyes . What's wrong with a few ifs and elses?
I've been (partly) successful using Exec instead of Run and capturing the stdout and putting the result into a variable. The code bolw does exactly what I need it to do, but... It does not run under DX. It runs from the desktop fine - suppresses the cmd window and puts stdout into a variable. I don't think Wscript attributes are visible from within DX. I get object undefined errors wherever I have Wscript when I run the script from inside a Dx object. Telling the object to use an external script (containing the code below) still results in the same errors.
However, I have found a better solution which still uses the Run command and does not use a file. I had a revelation of sorts...Output from most command line functions can be directed to a file using ">", but starting with Server 2003, this same output can be directed to the Clipboard using "|clip" .
I've replaced all of the file saving and reading stuff with:
strCommand = "netsh wlan show networks mode=bssid |clip"
oShell.run strCommand, 0, True
netshresults = System.Clipboard
In my code, I save the current clipboard contents into a temp variable before I put the netsh stuff into it, then read the clipboard into a variable so I can parse it up. I then put the original contents of the clipboard back.
I'm currently testing everything right now and everything seems to be working. I'll post the update tonight.
Code: vbscript
- Set oShell = CreateObject("WScript.Shell") ' Make script run in Cscript so we can capture the std out of the Exec command. ' Must run in cscript because under wscript there is no way to suppress the command window If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then oShell.Run "cscript """ & WScript.ScriptFullName & """", 0, False WScript.Quit End If ‘ execute command here strCommand = " netsh wlan show networks mode=bssi " set objShell = CreateObject("Wscript.Shell") set objProc = objShell.Exec(strCommand) Do
- WScript.Sleep 100 Loop Until objProc.Status <> 0 if objProc.ExitCode <> 0 then WScript.Echo "XXXXXX EXIT CODE: " & objProc.ExitCode WScript.Echo "XXXXXX ERROR: " & objProc.StdErr.ReadAll end if netsh_output = objProc.StdOut.ReadAll