Solved

Getting Wireless Connection Name Through VBA

Posted on 2014-01-28
4
1,948 Views
Last Modified: 2014-02-26
Is there any way for us to get the SSID of the Wifi or the name of the Local Area Network we are currently connected to?

Basically, I want to detect the name of the active connection, e.g. if it is the office network, then allow the script to resume, if it is the home network, or a public wifi etc, do not resume with script execution or provide an option to connect to a VPN of the office network.
0
Comment
Question by:jb702
4 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39816994
Hi,

maybe

LAN_Id = Environ("ComputerName")
UDomain = Environ("UserDomain")
Debug.Print UDomain
Debug.Print LAN_Id

Open in new window

Regards
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39817133
Function GetNameOfActiveConnection() As String

    Dim strComputer As String
    Dim objWMIService As Object, colLAN As Object, colWiFi As Object, objWifi As Object, objLAN As Object

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colLAN = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID like 'Local Area Connection' and PhysicalAdapter='True'")
    Set colWiFi = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID =" & "'" & GetWirlessName & "'" & "and PhysicalAdapter='True' ")

    For Each objWifi In colWiFi
        If objWifi.Netconnectionstatus = 2 Then
            GetNameOfActiveConnection = objWifi.Name
        End If
    Next

    For Each objLAN In colLAN
        If objLAN.Netconnectionstatus = 2 Then
            GetNameOfActiveConnection = objLAN.Name
        End If
    Next

End Function

Open in new window

0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39817461
Personally, I would recommend against using Access over a wireless connection, especially from a laptop or tablet that you are moving throughout your environment.  The potential for broken connections (and therefore data corruption) is much higher when using Access over wireless.

Additionally, wireless connections are significantly slower than wired and your application is likely to function extremely slowly.

Finally, if you seriously need this functionality, recommend you move your back-end to SQL Server or SQL Server express.
0
 

Author Closing Comment

by:jb702
ID: 39890882
Thank you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now