Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Find Network Connection exists or not?

Status
Not open for further replies.

vinidel

IS-IT--Management
Jan 23, 2004
78
0
0
US
Hi All,

Anyone knows what System object or any other method to find whether user machine is connected to network or not?


Thanks

 
SystemInformation.Network

It returns a boolean indicating if connected to a network.
 
Hi kmcdonag,

Thanks for your prompt reply.
I tried systeminformation.network, but its returning true in both the cases.
I unhooked my laptop from docking station and tried with detaching the network cable also, still it SystemInformation.Network returns TRUE.

I don't know what is wrong or may be its a bug.

Anyway thanks for your help.

Do let me know if you can think of something else.
 
Oops, my apologies. SystemInformation.Network returns hardware information not connection information (it meets my uses for it but is not applicable to your question). I will right my wrong; here is a function that will do what you need (this is not my code, it comes from a post by Dean Slindee on Google Groups):

Public Function IsNetworkAvailable() As Boolean
Dim NAQuery As New SelectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration()")
Dim NASearcher As New ManagementObjectSearcher(NAQuery)
Dim IsAvailable As Boolean = False
Dim IPEnabled As Boolean = False
Dim IPAddress() As String
Dim str As String
Try
Dim manObject As ManagementObject
For Each manObject In NASearcher.Get()
IPEnabled = CBool(manObject("IPEnabled"))
If IPEnabled Then
IPAddress = CType(manObject("IPAddress"), String())
If IPAddress(0) <> "0.0.0.0" Then
IsAvailable = True
str = IPAddress(0)
End If
End If
Next manObject
Catch exc As Exception
'Call ExceptionHandler(c_frmIdentity, exc)
'Return IsAvailable
End Try
Return IsAvailable
End Function 'IsNetworkAvailable
 
Am I suppose to add any references to run above pasted code. As compiler is not accepting keywords like

'SelectQuery'
'ManagementObjectSearcher'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top