Windows 7 - Collect Wireless Signal Strength via Command Line

Solution 1:

After much internal infighting, I utilized a combination of VBScript and command line. Since there doesn't appear to be a WMI methodology to grab the signal strength anymore, and since I'd prefer to collect the information over a short period of time and average it, I'm using VBScript to execute NETSH and pull the data I need.

This could absolutely be quickly modified to repeat endlessly so you could walk around with your laptop to determine signal strength in different areas (although, absolutely not recommended because far superior 3rd-party software packages exist).

====================================================================

dim obj_shell, obj_cmdexectestWLAN, var_line, obj_cmdexec, var_signalstrength, var_testinterval, var_counter, var_dots, var_arraycontents, var_item, var_average, var_multiplier, arr_signalstrength()
var_testinterval = 1000 'in milliseconds
var_counter = 0
var_dots = "." 'this is for a cheap progress bar

set obj_shell = wscript.createobject("WScript.Shell")
set obj_cmdexectestWLAN = obj_shell.exec("%comspec% /C netsh wlan show interfaces")
var_line = obj_cmdexectestWLAN.stdout.readline()
if instr(var_line, "not running") = 0 then

    function func_getwirelesssignalstrength()
        set obj_cmdexec = obj_shell.Exec("%comspec% /C netsh wlan show interfaces | FIND ""Signal""")
        var_line = obj_cmdexec.stdout.readline()
        var_line = replace(var_line,"Signal                 : ","")
        var_line = replace(var_line,"%","")
        var_line = trim(var_line)
        if isnumeric(var_line) then 
            func_getwirelesssignalstrength = var_line
        else
            func_getwirelesssignalstrength = "Error"
        end if
    end function

    do while var_counter < 10 '0-based. Gives us 10 samples. If you want a longer interval, you can modify both 'var_counter' at the top and this as well
        wscript.stdout.write(var_dots & chr(13))
        var_signalstrength = func_getwirelesssignalstrength()
        if isnumeric(var_signalstrength) then
            if var_counter = 0 then
                redim arr_signalstrength(0)
                arr_signalstrength(0) = var_signalstrength
            else
                redim preserve arr_signalstrength(ubound(arr_signalstrength) + 1)
                arr_signalstrength(ubound(arr_signalstrength)) = var_signalstrength
            end if
            var_counter = var_counter + 1
            var_dots = var_dots & "."
            wscript.sleep var_testinterval
        else
            wscript.echo("Error: Non-numeric value received from NETSH. Quitting...")
            wscript.quit
        end if
    loop

    for each var_item in arr_signalstrength
        var_arraycontents = var_arraycontents & var_item & ","
        var_multiplier = cint(var_multiplier) + cint(var_item)
    next
    var_average = var_multiplier/var_counter
    'wscript.echo("Multiplier:" & var_multiplier & vbcrlf & "Counter:" & var_counter & vbcrlf & "Average:" & var_average & vbcrlf & "Average Rounded:" & round(var_average,2)) 'test region to see our output in more detail
    wscript.echo("Values Received: " & var_arraycontents) 'test region to see our array contents
    wscript.echo("Signal Strength Average: " & round(var_average,2))

else
    wscript.echo("Error: WLAN Service Not Running")
    wscript.quit
end if