It has been a while since I last made a post here. But I intend to get up to speed and publish on a more regular basis. Anyway, on the .NET platform and with VB.NET we can rather easy check if the computer we work on is connected to a network or not.
To know that information allows us:
- To run methods that update workbooks with the latest data.
- Run network located templates and individual workbooks.
- Load network based add-ins.
Technically we will be using the My namespace to find out if the computer is connected or not. More specifically we will use the My.Computer namespace which provides methods to control the computer’s hardware and the system software. Among other things, it allows us to work with the file system, clipboard, Windows Registry network printers, network connection and keyboard & mouse.
The following snippet code shows how we can use it to determine if the computer is connected to a network.
Because the property isAvailable only indicates if there is a network available or not we need to make sure that there is a connection to the network we actually want to access. In order to do so we use the Ping function to insure that the wanted remote location is available.