Hi
I am putting together an app in vb6 (not a .Net coder as yet) that needs WiFi some of the time but not often and to preserve battery I would like to tell the user if WiFi is on when it needn't be.
I found an excellent shortcut on this site that pops out the Networks fly-out pane (thanks for that!) but I would like to test if the WiFi switch is on or off.
I found some code elsewhere that uses a WMIService call to get the name of the WiFi adapter if it is connected. That works but it returns a null string if either the WiFi is off or it is On but no WiFi connection has been chosen so it doesn't give me quite what I need.
The code for getting the WiFi name is shown at the bottom of this message. I am thinking it is the wrong way to go as it relates to the adapter not the Windows switch but not sure.
I had considered using the Airplane mode on/off that I also found on this site but I am having trouble getting back to my app after it runs and I would prefer the user to control it themselves anyway (hence the flyout)
To see what changed I exported the registry on the device (HP Stream 7 running WIn 8.1) with WiFi switched on and then again having switched it off
I then compared the text files and I found a flag that sounds promising called RFOff (it is 1 when WiFi is off and 0 when on). Am guessing RF is Radio something
It is. however, deep in the CurrentControlSet001 under ....
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0000]
a couple of the values (there are many) are ...
"DriverDesc"="Realtek RTL8723BS Wireless LAN 802.11n SDIO Network Adapter"
"RFOff"=dword:00000000
Assuming I am right and that flag is the marker for the WiFi switch then how would I find it on any given machine (I have several to set up so assuming they wouldn't all have the same GUID for the WiFi device)
All I need to do is test for it, not intention of setting it. If WiFi is On then I can pop out the flyout pane
Any help gratefully received!
Thanks
Simon
Here is the code for detecting the WiFi name.
bIsWifiOn = False
On Error Resume Next
sComputer = "."
Set oWMIService = GetObject("winmgmts:" & sComputer & "\root\CIMV2")
Set colWifi = oWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" & sGetWirelessName & "'" & "and PhysicalAdapter='True' ")
Dim sSt As String
Dim sSi As String
If Not colWifi Is Nothing Then
For Each oWifi In colWifi
If oWifi.Netconnectionstatus = 2 Then
If Trim(oWifi.Name) <> "" Then bIsWifiOn = True
End If
Next
End If
I am putting together an app in vb6 (not a .Net coder as yet) that needs WiFi some of the time but not often and to preserve battery I would like to tell the user if WiFi is on when it needn't be.
I found an excellent shortcut on this site that pops out the Networks fly-out pane (thanks for that!) but I would like to test if the WiFi switch is on or off.
I found some code elsewhere that uses a WMIService call to get the name of the WiFi adapter if it is connected. That works but it returns a null string if either the WiFi is off or it is On but no WiFi connection has been chosen so it doesn't give me quite what I need.
The code for getting the WiFi name is shown at the bottom of this message. I am thinking it is the wrong way to go as it relates to the adapter not the Windows switch but not sure.
I had considered using the Airplane mode on/off that I also found on this site but I am having trouble getting back to my app after it runs and I would prefer the user to control it themselves anyway (hence the flyout)
To see what changed I exported the registry on the device (HP Stream 7 running WIn 8.1) with WiFi switched on and then again having switched it off
I then compared the text files and I found a flag that sounds promising called RFOff (it is 1 when WiFi is off and 0 when on). Am guessing RF is Radio something
It is. however, deep in the CurrentControlSet001 under ....
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0000]
a couple of the values (there are many) are ...
"DriverDesc"="Realtek RTL8723BS Wireless LAN 802.11n SDIO Network Adapter"
"RFOff"=dword:00000000
Assuming I am right and that flag is the marker for the WiFi switch then how would I find it on any given machine (I have several to set up so assuming they wouldn't all have the same GUID for the WiFi device)
All I need to do is test for it, not intention of setting it. If WiFi is On then I can pop out the flyout pane
Any help gratefully received!
Thanks
Simon
Here is the code for detecting the WiFi name.
bIsWifiOn = False
On Error Resume Next
sComputer = "."
Set oWMIService = GetObject("winmgmts:" & sComputer & "\root\CIMV2")
Set colWifi = oWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" & sGetWirelessName & "'" & "and PhysicalAdapter='True' ")
Dim sSt As String
Dim sSi As String
If Not colWifi Is Nothing Then
For Each oWifi In colWifi
If oWifi.Netconnectionstatus = 2 Then
If Trim(oWifi.Name) <> "" Then bIsWifiOn = True
End If
Next
End If
My Computer
System One
-
- OS
- Windows 8.1