Solved Confirm LAN connection. (2 Viewers)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Hi, i'm looking for a way of determining whether an access db is being accessed via LAN or WiFi. This seems to be a perrenial question. I downloaded Daniel Pinaults solution, but it always returns 'true', LAN or WiFi connected. I've been Googling, but the more i read, the more confused i become. Ideally, i'd like to check for a LAN connection prior to opening the database. I'm trying to avoid cases where a user logs onto the database via WiFi, which with laptops is all too easy. Appreciate any assistance.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:30
Joined
Feb 28, 2001
Messages
27,183
Look at the first entry in Similar Threads below.

Colin (Isladogs) and I researched this in some depth and both of us came up nearly blank. The little bit we found is not at all definitive in its answer. I still have not come across a definitive way to do this that doesn't involve Windows system (API) calls that trace their way through system-memory-resident networking (device driver) structures.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:30
Joined
May 7, 2009
Messages
19,242
check this code:
Code:
' http://randoltech.blogspot.com/2015/05/vbscript-to-check-wireless-or-wired.html
'
' modified by arnelgp for VBA use.
'
Public Function chkConnectionType() As String

'==================================================================
'
' NAME:  Check Connection Type
'
' AUTHOR: Mark Randol
' DATE  : 4/29/2015
'
' COMMENT: this script will return
'          1 if the both are in use (shouldn't happen, but can)
'          2 if wired LAN adapter is in use
'          3 if wireless LAN adapter is in use
'          4 if none of the LAN adapters are in use.
'==================================================================

On Error Resume Next

Dim strComputer
Dim objWMIService
Dim colWiFi
Dim colLAN
Dim objWifi
Dim objLAN
Dim state
Dim wireStatus
Dim wifiStatus
Dim strOut
Dim intOutput

'arnelgp
Dim strReturn As String
'===================================================================================
' Initialize Variables
'===================================================================================

intOutput = 4
state = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionStatus = 2 and PhysicalAdapter = 'True'")

'==================================================================
' Enumerate the wired adapters in WMI.  Add 1 to output if wired adapter is in use.
'==================================================================

'WScript.Echo ("Output starting at " & intOutput)
'Debug.Print ("Output starting at " & intOutput)

For Each objLAN In colLAN
    strOut = objLAN.NetConnectionID & " " & objLAN.Name & " " & objLAN.PhysicalAdapter
    If InStr(LCase(objLAN.Name), "virtual") = 0 And InStr(LCase(objLAN.Name), "multiplex") = 0 And InStr(LCase(objLAN.Name), "bridge") = 0 Then
       '==================================================================
' Above line (if statement) is there to eliminate other extraneous adapters that
' still show up even though we are eliminating all but "physical" adapters.  Some
' virtual adapters are still there, Microsoft being the biggest offender.
' Add to the line if necessary to remove other non-physical adapters.
'==================================================================

        If InStr(LCase(objLAN.NetConnectionID), "wireless") > 0 Or InStr(LCase(objLAN.NetConnectionID), "wi-fi") > 0 Then
            intOutput = intOutput - 2
            'WScript.Echo (strOut & " connected.  Output is now " & intOutput)
            'Debug.Print (strOut & " connected.  Output is now " & intOutput)
            strReturn = "wi-fi"
        End If
        If InStr(LCase(objLAN.NetConnectionID), "wireless") = 0 And InStr(LCase(objLAN.NetConnectionID), "wi-fi") = 0 Then
            intOutput = intOutput - 1
            'WScript.Echo (strOut & " connected.  Output is now " & intOutput)
            'Debug.Print (strOut & " connected.  Output is now " & intOutput)
            strReturn = "wired"
        End If
    End If
Next

'WScript.Echo ("Final Output = " & intOutput)
'WScript.Echo (intOutput)
'WScript.Quit (intOutput)

'Debug.Print ("Final Output = " & intOutput)
'Debug.Print (intOutput)

chkConnectionType = strReturn
End Function
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
It is certainly possible to detect whether the workstation has a wired or wireless connection and whether or not WiFi is switched on.
Of course it doesn't matter whether WiFi is in use when a split database has BE tables on the same PC
The difficulty is in detecting whether a database with linked BE tables on a network is actually connected to the network using WiFi.

The attached database has a module with two different routines: IsWiFiConnected & IsWiFiConnectionInUse.
This was the result of a lengthy discussion at UA. The latter procedure came close but its still not 100% reliable
Hopefully someone will be able to take it a stage further

EDIT
I just tried the code @arnelgp supplied on my tablet which only has Wifi. It wrongly reported a wired connection
 

Attachments

  • WiFiCodeTest.accdb
    344 KB · Views: 301

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:30
Joined
May 7, 2009
Messages
19,242
I just tried the code @arnelgp supplied on my tablet which only has Wifi. It wrongly reported a wired connection
i did also a test. i only have wi-fi and it Passed the test.
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
Hi @arnelgp
Just checked the code you gave
There are several ways that WiFi may be 'registered'. The code you gave looks for "wireless" or "Wi-fi"

However my adapter shows as "Wifi" so your code misses that connection.
It should therefore record no connection ....not wired

NOTE:
A better check (as used in the code I uploaded) is for "Wi*Fi" or "Wireless"
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Gents, thanks. Will let you know how I progress.
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
Please do.
I have a plan for implementing the checks mentioned in line 3 of post #4 but it would be helpful to get further feedback on how well the code works. From my tests, I know it correctly identifies when WiFi is switched on and when switched off
But there is one significant hurdle still to verify.
Does the code correctly identify the connection used on e.g. a laptop with both WiFi switched on and an Ethernet connection.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Gents, so I installed both modules in a database on a network drive. I connected my laptop to the network alternately via LAN & via WiFi. Then opened the database. In the immediate window I typed '?IsWiFiConnectionInUse' or '?IsWiFiConnected'. In both instances I get false as a result. Am I testing correctly?. Also, Isladogs both routines give exactly same result.

arnelgp's code seems to work OK & correctly identified when I was connected via LAN or WiFi. Cheers.
 
Last edited:

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Gents, Have trialled arnelgps code a lot & seems to work fine. Thanks to all whom assisted.
 

vhung

Member
Local time
Today, 13:30
Joined
Jul 8, 2020
Messages
235
Good day...
Checking Internet Connection Type using “vba” on “msaccess” is so wonderful.

NAME: Check Connection Type
' AUTHOR: Mark Randol
' DATE : 4/29/2015

"modified by arnelgp for VBA use."

I used:
If chkConnectionType = "wi-fi" Then
MsgBox "Your Internet Connection Type is {Wi-Fi}.", vbInformation
End If

See attachment...
 

Attachments

  • ConnectionType.png
    ConnectionType.png
    121 KB · Views: 310
Last edited:

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Vhung, thanks. I do something similar! I wonder whether it's reasonable to close the application upon detection of a wi-fi connection or not? My fear is laptop users, whom may not connect a LAN cable uppon setting up.
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
I think that terminating an Access app on detecting a Wifi connection when it may not be in use is going to annoy your users.
The alternative of disabling Wifi from an Access app is also problematic as it could potentially cause the corruption you are trying to avoid.
So its a bit of a Catch-22 situation.

An alternative suggested in another thread might be to disable WiFi using a script then open the Access app.
See Tips on General DB Deployment and/or Management | Access World Forums (access-programmers.co.uk)
A desktop shortcut could be used to run the script
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Colin, Thanks you confirmed my suspicions. I think I'll just continue with my start up message something like '...You are connected via Wi-Fi, this may result in corruption, Do you wish to continue ?..'
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
Perhaps change the message to
You appear to be using a WiFi connection. This is very likely to cause corruption. Please close Access, turn off WiFi and reconnect using an Ethernet cable.
Perhaps they will comply!
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 09:30
Joined
Apr 1, 2019
Messages
731
Yep, cannot make it much clearer than that. Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:30
Joined
Sep 21, 2011
Messages
14,297
Perhaps change the message to

Perhaps they will comply!
In laptops I have used and this one is no different, if I connect an ethernet cable, the wifi is disabled?
 

isladogs

MVP / VIP
Local time
Today, 21:30
Joined
Jan 14, 2017
Messages
18,219
In laptops I have used and this one is no different, if I connect an ethernet cable, the wifi is disabled?
Interesting and I wish that were always true. Certainly not the case with my laptop!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:30
Joined
Feb 28, 2001
Messages
27,183
That "auto-disconnect" may depend more on whether you have a "home" or a "pro" version of Windows. I recall that one difference between "Home" and "Pro" USED to be that you could only have one network connection active at a time because "Home" wasn't allowed to act as a router or gateway. "Home" didn't have all the necessary net tools for being anything other than an end node. Don't know if that still applies.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:30
Joined
Sep 21, 2011
Messages
14,297
Doc,
This laptop is Win10 Pro Ver 20H2. Acer Aspire 7720
I'll have to try on the other laptop when switched on, as that is a Home version.
I do remember one laptop, where it even came up as a message on the desktop, each time the status of the wifi changed. :)

I was just putting it out there anyway, and Colin has confirmed not all laptops have the feature.?
 

Users who are viewing this thread

Top Bottom