UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
3 Pages V < 1 2 3  (Go to first unread post)
   Reply to this topicStart new topic
> Is There A Way To Detect A Wireless Connection To The Backend File?, Access 2016    
 
   
appro
post Jul 12 2017, 08:44 PM
Post#41



Posts: 153
Joined: 23-January 05



QUOTE
Are you referring to ListNetworkConnections? If so, the MediaSubType never changes regardless of the connection status.


I was referring to the ListNetworkConnections.
Go to the top of the page
 
DanielPineault
post Jul 12 2017, 08:53 PM
Post#42


UtterAccess VIP
Posts: 5,281
Joined: 30-June 11



Okay, that is completely normal then as the MediaSubType never changes, but this make your question as to why IsConnectedbyWireless isn't working reliably even more perplexing.

I'm going to call it a night and will try and think about it.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
DanielPineault
post Jul 13 2017, 09:18 AM
Post#43


UtterAccess VIP
Posts: 5,281
Joined: 30-June 11



Since you seem to be indicating that the GetWirlessNames() is properly identifying the wireless apdater since the MediaSubType does come back as 2, we'd need to explore why IsConnectedbyWireless() isn't recognizing the fact that it is active, or not. The only thing I can figure is it has to do with the NetConnectionStatus filter that I use to extract those that are 1=Connecting, 2=Connected. Perhaps your adapter has another status for some reason and we'd need to add it to the filter as well. As such, try running the following which should provide you a list of wireless adapters and their current status (so run it connected, and disconnected to see what the status values are). Post back with your finding. Hopefully this will identify what we need to tweak to make it work.


CODE
Public Function WirelessStatus()
    'Ref: https://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
    Dim oWMI                  As Object
    Dim oWirelessAdapters     As Object
    Dim oWirelessAdapter      As Object
    Dim WirelessNames         As Collection
    Dim i                     As Long

    Set WirelessNames = GetWirelessNames()

    On Error GoTo Error_Handler

    Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    For i = 1 To WirelessNames.Count
        Set oWirelessAdapters = oWMI.ExecQuery("SELECT *" & vbCrLf & _
                                               " FROM Win32_NetworkAdapter" & vbCrLf & _
                                               " WHERE NetconnectionID = '" & WirelessNames(i) & "'" & _
                                               "       AND PhysicalAdapter='True'")
        For Each oWirelessAdapter In oWirelessAdapters
            With oWirelessAdapter
                Debug.Print Nz(.NetconnectionID), , _
                            .NetConnectionStatus & " -> " & GetNetConnectionStatus(.NetConnectionStatus)
            End With
        Next oWirelessAdapter
    Next i

Error_Handler_Exit:
    On Error Resume Next
    Set WirelessNames = Nothing
    Set oWirelessAdapter = Nothing
    Set oWirelessAdapters = Nothing
    Set oWMI = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: WirelessStatus" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit
End Function

Function GetWirelessNames() As Collection
    'Greatly inspired from: https://gallery.technet.microsoft.com/scriptcenter/Disable-wireless-f3bcf66f#content
    Dim strKeyPath            As String
    Dim strComputer           As String
    Dim objReg                As Object
    Dim arrSubKeys
    Dim SubKey
    Dim strValueName          As String
    Dim dwValue
    Dim strValue              As String
    Const HKLM = &H80000002
    Dim WirelessNames          As Collection

    Set WirelessNames = New Collection

    strKeyPath = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
    strComputer = "."

    Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    objReg.Enumkey HKLM, strKeyPath, arrSubKeys

    For Each SubKey In arrSubKeys
        strValueName = "MediaSubType"
        objReg.GetDWORDValue HKLM, strKeyPath & "\" & SubKey & "\" & "Connection", strValueName, dwValue
        If dwValue = 2 Then
            strValueName = "Name"
            objReg.GetStringValue HKLM, strKeyPath & "\" & SubKey & "\" & "Connection", strValueName, strValue
            WirelessNames.Add strValue
            '            Exit For
        End If
    Next

    Set GetWirelessNames = WirelessNames
    Set WirelessNames = Nothing
    Set objReg = Nothing
End Function

Private Function GetNetConnectionStatus(lNetConStatus As Variant) As String
    If IsNull(lNetConStatus) = True Then lNetConStatus = -1
    Select Case lNetConStatus
        Case 0
            GetNetConnectionStatus = "Disconnected "
        Case 1
            GetNetConnectionStatus = "Connecting"
        Case 2
            GetNetConnectionStatus = "Connected"
        Case 3
            GetNetConnectionStatus = "Disconnecting"
        Case 4
            GetNetConnectionStatus = "Hardware Not Present"
        Case 5
            GetNetConnectionStatus = "Hardware Disabled"
        Case 6
            GetNetConnectionStatus = "Hardware Malfunction"
        Case 7
            GetNetConnectionStatus = "Media Disconnected"
        Case 8
            GetNetConnectionStatus = "Authenticating"
        Case 9
            GetNetConnectionStatus = "Authentication Succeeded"
        Case 10
            GetNetConnectionStatus = "Authentication Failed"
        Case 11
            GetNetConnectionStatus = "Invalid Address"
        Case 12
            GetNetConnectionStatus = "Credentials Required"
        Case Else
            GetNetConnectionStatus = "Unknown status"
    End Select
End Function

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
appro
post Jul 13 2017, 05:52 PM
Post#44



Posts: 153
Joined: 23-January 05



Thanks for persisting with this Daniel. I've run your code on 3 Windows 10 laptops. On the 2 laptops running Access 2010 32 bit, running "WirelessStatus" in the Immediate window gives no result both with wifi connected and disconnected.

On the third laptop that is running Access 2013 64 bit, running "WirelessStatus" in the immediate window reliably gives the correct results i.e. "Wi-Fi 2 -> Connected" when wifi is connected and "Wi-Fi 7 -> Media Disconnected" when wifi is disconnected.

On all 3 machines "GetNetConnectionStatus" yields no result when run in the immediate window.
Go to the top of the page
 
ridders
post Jul 14 2017, 03:38 PM
Post#45



Posts: 212
Joined: 15-January 17
From: Somerset UK


Hi

Just dipped back into this thread and have tested Daniel's latest code on a Win10 laptop using Access 2016 64-bit

WirelessStatus gives
a) Wi-Fi 2 -> Connected with WiFi on
b) Wi-Fi 7 -> Media Disconnected with Wifi ON BUT using Ethernet connection
c) Wi-Fi 7 -> Media Disconnected with Wifi OFF

On a Win10 desktop using Access 2010 32-bit with no wifi connection, WirelessStatus gives no result (as you would expect)

HTH
This post has been edited by ridders: Jul 14 2017, 03:40 PM

--------------------
Colin

Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10, Website, email
Go to the top of the page
 
ridders
post Jul 14 2017, 04:10 PM
Post#46



Posts: 212
Joined: 15-January 17
From: Somerset UK


Daniel

Have you tried running either of these subroutines EnableWireless / DisableWireless which are also from https://gallery.technet.microsoft.com/scrip...3bcf66f#content

I've had no success so far with these in VBA

Also forgot to say that your updated function IsConnectedByWireless from post 16 gives the correct results on my Win10 laptop using Access 2016 64-bit:
WiFi ON = True
WiFi ON but Ethernet connection in use = False
WiFi OFF = False


This post has been edited by ridders: Jul 14 2017, 04:29 PM

--------------------
Colin

Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10, Website, email
Go to the top of the page
 
DanielPineault
post Jul 15 2017, 06:57 AM
Post#47


UtterAccess VIP
Posts: 5,281
Joined: 30-June 11



Thanks for reporting back.

No, I haven't tested the scripts out beyond repurposing the GetWirlessName function.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
adrianscotter
post Jul 16 2017, 06:03 AM
Post#48



Posts: 25
Joined: 24-February 13
From: Norwich, UK or Lehigh Acres, FL


Just thinking out loud here for people with security concerns from earlier in this post, would O & O Shutup work for you with Windows 10? I use it and love it. Basically, it turns off nearly all of the Microsoft telemetry and lets you decide what and where things go.



As for the wireless bit, I'd use MAC filtering in the router to dis-allow that laptop from connecting via a wireless connection. As far as I'm concerned, if they (end users) don't do as I ask, I enforce it. The wirelss on the laptop will work everywhere else, just not on my network. If it's awkward for them to not have wireless in the office, that's their problem for not doing as I asked in the first place. Or am I being unkind? smile.gif
This post has been edited by adrianscotter: Jul 16 2017, 06:08 AM

--------------------
Jack of all trades, master of none!
Go to the top of the page
 
DanielPineault
post Jul 16 2017, 07:21 AM
Post#49


UtterAccess VIP
Posts: 5,281
Joined: 30-June 11



QUOTE
Just thinking out loud here for people with security concerns from earlier in this post, would O & O Shutup work for you with Windows 10? I use it and love it. Basically, it turns off nearly all of the Microsoft telemetry and lets you decide what and where things go.

Never heard of it. I'll need to do some research but I'm always leery of unknown 3rd party free products.

QUOTE
As for the wireless bit, I'd use MAC filtering in the router to dis-allow that laptop from connecting via a wireless connection. As far as I'm concerned, if they (end users) don't do as I ask, I enforce it. The wireless on the laptop will work everywhere else, just not on my network. If it's awkward for them to not have wireless in the office, that's their problem for not doing as I asked in the first place. Or am I being unkind? smile.gif

That is a very viable solution for some. In my case, with some clients that would not work as they need access to both LAN and wireless, so we couldn't apply such a rule, but it is definitely a solution that could work reliably for some.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
3 Pages V < 1 2 3


Custom Search
RSSSearch   Top   Lo-Fi    21st October 2017 - 01:37 AM