Question Detect if database opened with a wireless connection

ghudson

Registered User.
Local time
Today, 03:58
Joined
Jun 8, 2002
Messages
6,194
Anyone have a fail proof way to detect if a user has opened a database with a wireless connection? I found this code @ http://www.experts-exchange.com/Sof...Office_Suites/MS_Office/Excel/Q_23102110.html but I am not able to test it since I do not have access to a wireless connection. Anyone have a moment to test if the IsInternetConnectionWireless() function will really test TRUE if you are running the code while your computer is connected to a wireless network? The TesingConnectionType() function will quickly run all three tests. Thanks!

Code:
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
 
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
 
Public Sub TesingConnectionType()

    Call IsInternetConnectionLAN
    MsgBox "IsInternetConnectionLAN = " & IsInternetConnectionLAN
    
    Call InternetConnected
    MsgBox "InternetConnected = " & InternetConnected
    
    Call IsInternetConnectionWireless
    MsgBox "IsInternetConnectionWireless = " & IsInternetConnectionWireless

End Sub
 
Public Function IsInternetConnectionLAN() As Boolean
On Error GoTo Err_IsInternetConnectionLAN

    Dim Result As Boolean
    Dim Flags As Long
 
    Result = InternetGetConnectedState(Flags, 0&)
    If Flags > 0 Then
        IsInternetConnectionLAN = True
    End If

Exit_IsInternetConnectionLAN:
    Exit Function

Err_IsInternetConnectionLAN:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "IsInternetConnectionLAN()"
    Resume Exit_IsInternetConnectionLAN
 
End Function
 
Private Function InternetConnected()
On Error GoTo Err_InternetConnected

    If InternetCheckConnection("http://www.google.com/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
        InternetConnected = False
    Else
        InternetConnected = True
    End If

Exit_InternetConnected:
    Exit Function

Err_InternetConnected:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "InternetConnected()"
    Resume Exit_InternetConnected

End Function
 
Public Function IsInternetConnectionWireless() As Boolean
On Error GoTo Err_IsInternetConnectionWireless

    IsInternetConnectionWireless = Not IsInternetConnectionLAN And InternetConnected

Exit_IsInternetConnectionWireless:
    Exit Function

Err_IsInternetConnectionWireless:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "IsInternetConnectionWireless()"
    Resume Exit_IsInternetConnectionWireless

End Function

I am correctly getting True for the IsInternetConnectionLAN and InternetConnected functions and a False for the IsInternetConnectionWireless function so I am hoping that the IsInternetConnectionWireless function will correctly test True when run from a computer connected wirelessly. Thanks!
 
I have Wireless and get

IsInternetConnectionLAN = True (it is actually False)
InternetConnected = True
IsInternetConnectionWireless = False (it is actually True)

I have no cable and rely on wireless. The database is local so no network connectivity is required. I don't connect an Access database with wireless.

It appears that all this is doing is checking the GetConnectedState andd that means LAN = True and therefore Wirelesss must be False.

Generally speaking the Wireless IP addresses are a specific range so as not to clash with LAN users who may use Static internal IP addresses. You maybe able to identify users in this range of wireless users.

Simon
 
Last edited:
Simon_MT, thanks for testing the code. Bummer that it is not working. I just found this bit of code that might do what I want. Could you test this and see if it returns True for you? I get False which should be correct since I am not connected wirelessly if this code really works.

Code:
Private Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" (ByVal strDrive As String) As Long

Public Function IsNetwork() As Boolean

    Const DRIVE_REMOTE = 4
    
    Dim strDriveName As String
    
    strDriveName = Left$(CurrentDb.Name, 2)
    
    IsNetwork = (GetDriveType(strDriveName) = DRIVE_REMOTE)

    MsgBox "IsNetwork = " & IsNetwork

End Function
 
Generally speaking the Wireless IP addresses are a specific range so as not to clash with LAN users who may use Static internal IP addresses. You maybe able to identify users in this range of wireless users.

Simon

Just a caution - this is model-specific and in fact nobody is restricted to using only that range. It's more of a convention than anything else and thus would not be a good general solution for identifying a wireless user.

One thing I'd want to do is investigate the Connection Adapter that we see in "My Network Settings" - IINM, we would have two separate adapter, one for wireless and one for ethernet so checking if the wireless is active may be more reliable. Maybe find an API that interrogate the properties of those adapters?
 
The general consensus using Access via a wireless connnect is not a great idea. It is a different story if a Terminal Server is used as a ample Session Timeout protects any interruption to the Session.

Simon
 
Well, yes, but I don't think it'd matter since from Access' POV, the connection is going to be not wireless - only the Terminal client would know whether the user has connected wirelessly and Access' VBA would be running in server's context and not client's so it has no idea how the user is manipulating the session. I imagine Ghudson is trying to block wireless users from using Access backend even in a local network.
 
I imagine Ghudson is trying to block wireless users from using Access backend even in a local network.

That is correct. I have a group of remote users who connect wirelessly to the network when they are out of the office. I know that some are still accessing the database wirelessly even though I have told them not to do it. I need to be able to identify if the user opens their front end wirelessly so that I can shut down their database if they open their front end wirelessly.

First time I have ever had to worry about this and I am surprised that I cannot find anything through searching the internet on how to detect if a user is wirelessly connected to the network.
 
Simon_MT, thanks for testing the code. Bummer that it is not working. I just found this bit of code that might do what I want. Could you test this and see if it returns True for you? I get False which should be correct since I am not connected wirelessly if this code really works.

Code:
Private Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" (ByVal strDrive As String) As Long

Public Function IsNetwork() As Boolean

    Const DRIVE_REMOTE = 4
    
    Dim strDriveName As String
    
    strDriveName = Left$(CurrentDb.Name, 2)
    
    IsNetwork = (GetDriveType(strDriveName) = DRIVE_REMOTE)

    MsgBox "IsNetwork = " & IsNetwork

End Function

Anybody have a chance to see if this code works to detect if your computer is connected wirelessly?
 
Come to think of it, you're right. Surely someone already had similar problem and would have thought to do this. Guess it was just not widely shared, maybe?

I think this would be where I'd start. Either IEnumNetworkConnections & INetworkConnection or INetworkListManager may be what we want to programatically interrogate the current network status. Unfortunately, this seems to be Vista and later only so if you have any XP clients, we would need to look for another API. I can't find a quick reference of what older API that would be replaced by those APIs linked but maybe that'll give you a starting point, hopefully?
 
Anybody have a chance to see if this code works to detect if your computer is connected wirelessly?

Not working ghudson. If I run it locally it returns false on both wired and wireless, and if I run from a network shared folder it returns True on both :eek:

Not what you wanted to hear I'm afraid.
 
Not working ghudson. If I run it locally it returns false on both wired and wireless, and if I run from a network shared folder it returns True on both :eek:

Not what you wanted to hear I'm afraid.

John, thanks for testing the code.

Dang I wish there was a VBA solution to test if a user is connected wirelessly to a network.
 
I had a think about this and using DHCP. Most wireless now allow you to assign IP addresses and DNS addresses using DHCP. One way to get around this problem would be to assign a specific IP range for wireless users between, for example, 192.168.1.100 to 192.168.149. Then you should be able to test if the IP address is within this range the connection must be wireless.

I know this is not what you want and there should be a more elegant way of doing this but using a range of IP address might worth considering.

Simon
 
Unfortunately I do not have any control over the IP addresses they use for wireless and hardwired.
 
Even so, look at the Ipconfig settings on the wirelessly connected PC's a good IT Manager generally instils some sort of structure in their IP connections.

Simon
 

Users who are viewing this thread

Back
Top Bottom