Call us! 512-349-0334 or (877) INDUSOFT

Using a Function in InduSoft Web Studio to Return your Wireless Network Name

GETSSID is a small sample app for InduSoft Web Studio HMI software that uses a function defined in the main procedures called GetSSID. It is created using various VBScript Class Objects and their Properties which returns name of the wiress network that your computer is connected to in a MessageBox. If your computer is not connected to a wireless network, the MessageBox is blank. The function is called from a script in a button object on a popup screen.

Download the InduSoft Web Studio Sample Application: GetSSID

Here is the function GetSSID:

Function GetSSID()

 

On Error Resume Next

Dim objFSO : Set objFSO  = CreateObject( “Scripting.FileSystemObject” )

If Err.Number <> 0 Then

$Trace(“Could not create Scripting.FileSystemObject, error = ” & CStr(Err.Number) & “: ” & Err.Description)

Exit Function

End If

Dim stdout : stdout = objFSO.GetTempName

 

Dim objWSH : Set objWSH = CreateObject( “WScript.Shell” )

If Err.Number <> 0 Then

$Trace(“Could not create WScript.Shell object, error = ” & CStr(Err.Number) & “: ” & Err.Description)

Set objFSO = Nothing

Exit Function

End If

Dim cmd : cmd = “cmd /c netsh.exe wlan show interfaces 1> “”” & stdout & “”””

objWSH.Run cmd, 0, True

If Err.Number <> 0 Then

$Trace(“Error running netsh.exe, error = ” & CStr(Err.Number) & “: ” & Err.Description)

Set objFSO = Nothing

Set objWSH = Nothing

Exit Function

End If

Dim objFile : Set objFile = objFSO.OpenTextFile(stdout,1)

If Err.Number <> 0 Then

$Trace(“Error cannot open stdout, error = ” & CStr(Err.Number) & “: ” & Err.Description)

Set objFSO = Nothing

Set objWSH = Nothing

Exit Function

End If

Dim arrLines : arrLines = Split(objFile.ReadAll,vbCrLf)

objFile.Close

objFSO.DeleteFile stdout

Set objFile = Nothing

Set objFSO = Nothing

Set objWSH = Nothing

Dim objRegExp : Set objRegExp = New RegExp

If Err.Number <> 0 Then

$Trace(“Error cannot create RegExp object, error = ” & CStr(Err.Number) & “: ” & Err.Description)

Exit Function

End If

objRegExp.Pattern = “^\s*SSID\s*:\s*”

objRegExp.IgnoreCase = True

Dim line : For Each line In arrLines

If objRegExp.Test(line) Then

If GetSSID <> “” Then GetSSID = GetSSID & “,”

GetSSID = GetSSID & objRegExp.Replace(line,””)

End If

Next

Set objRegExp = Nothing

End Function

The function basically performs the following tasks (not in the exact sequence shown below):

1)      Creates various VBScript Class Objects

2)      Uses the command line: “cmd /c netsh.exe wlan show interfaces 1” (see below) to return the wireless system information to a variable and writes the information to a temporary text file located in your project root directory.

3)      Parses each line to find the “SSID” and displays that value in a MessageBox

4)      Deletes the tremporary file.

5)      Utilizes various error handling throughout the function operation.

Note that the Properties of various System and File Class objects are used, and may require some advanced programming experience in VB Scripting in order to fully understand the operation of this function. Microsoft has a helpful webpage which can take you through some of the functionality used within this function and sample application.

getssid

Please feel free to leave any comments about this sample app in the InduSoft Web Studio forum post located here.

Comments are closed.