Hello. I am trying to automate the process of connecting manually to the WiFi network before running my XOJO application on a windows 11 PC. It connects to a micro controller via WiFi.
I have searched and found some useful information in the forum. Thanks to those that have shared their code.
The problem that I first encountered is that the WiFi list needs to be refreshed or the netsh command will return an error more often than not. I thought that there would be an easy way to refresh the list from the shell command but I was wrong.
The only way I have found is this shell command
‘explorer.exe ms-availablenetworks’. it works every time, but opens the WiFi networks connection dialog. It’s not a deal breaker but it does require human intervention to close by just clicking anywhere off of the dialog box.
I am wondering if anyone has done this in a more elegant manner that would share it.
Thanks again.
This is the code I have in the opening event for the window.
Var sh As New Shell
var cmd As String
cmd= "explorer.exe ms-availablenetworks:"
sh.Execute (cmd)
do
App.DoEvents(25)
Loop Until Not sh.IsRunning
cmd = "netsh wlan connect ssid=swp_1 name=swp_1"
sh.Execute (cmd)
do
App.DoEvents(25)
Loop Until Not sh.IsRunning
if sh.ExitCode = 0 then
sh.Close
Dim screenWidth As Integer = DesktopDisplay.DisplayAt(0).Width
Dim screenHeight As Integer = DesktopDisplay.DisplayAt(0).Height
me.Left = 20
me.Top = screenHeight - 400
tmrConnTimeout.RunMode = Timer.RunModes.Single
dim devAdd as String = "http://" + devIP + "/?|19|"
WebConn.Disconnect
WebConn.Send("GET", devAdd)
else
MessageBox(sh.Result)
sh.close
Quit
end If
6 posts - 2 participants