IT Community - Software Programming, Web Development and Technical Support

Network Connection Checking - Using API

This is a discussion on Network Connection Checking - Using API within the VB.NET Programming forums, part of the Software Development category; We can check the network connection is available or not by using WININET APIs. I have implemented the wininet.dll ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-27-2007, 03:02 PM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Network Connection Checking - Using API

We can check the network connection is available or not by using WININET APIs. I have implemented the wininet.dll function in VB6 sample application


Declare the following API constants and variables in form general declaration part

Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long 'Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long 'this function used with IE4
'Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long 'this function used with IE4
Private Const INTERNET_CONNECTION_MODEM = &H1&
Private Const INTERNET_CONNECTION_LAN = &H2&
Private Const INTERNET_CONNECTION_PROXY = &H4&
Private Const INTERNET_RAS_INSTALLED = &H10&
Private Const INTERNET_CONNECTION_OFFLINE = &H20&
Private Const INTERNET_CONNECTION_CONFIGURED = &H40&


Add the following functions to your form

Private Sub NetConnectionCheck(Optional ByRef ConnectionInfo As Long, Optional ByRef sConnectionName As String)
Dim dwFlags As Long
Dim sNameBuf As String, msg As String
Dim lPos As Long
sNameBuf = String$(513, 0)
If InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&) Then
lPos = InStr(sNameBuf, vbNullChar)
If lPos > 0 Then
sConnectionName = Left$(sNameBuf, lPos - 1)
Else
sConnectionName = ""
End If
msg = "Your computer is connected to Internet" & vbCrLf & "Connection Name: " & sConnectionName

If (dwFlags And INTERNET_CONNECTION_LAN) Then
msg = msg & vbCrLf & "Connection use LAN"
ElseIf lFlags And INTERNET_CONNECTION_MODEM Then
msg = msg & vbCrLf & "Connection use modem"
End If

If lFlags And INTERNET_CONNECTION_PROXY Then msg = msg & vbCrLf & "Connection use Proxy"

If lFlags And INTERNET_RAS_INSTALLED Then
msg = msg & vbCrLf & "RAS INSTALLED"
Else
msg = msg & vbCrLf & "RAS NOT INSTALLED"
End If

If lFlags And INTERNET_CONNECTION_OFFLINE Then
msg = msg & vbCrLf & "You are OFFLINE"
Else
msg = msg & vbCrLf & "You are ONLINE"
End If

If lFlags And INTERNET_CONNECTION_CONFIGURED Then
msg = msg & vbCrLf & "Your connection is Configured"
Else
msg = msg & vbCrLf & "Your connection is not Configured"
End If
Else
msg = "Your computer is NOT connected to Internet"
End If
MsgBox msg, vbInformation, "Checking connection"
End Sub
just call the function "NetConnectionCheck()"

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Karpagarajan : 03-27-2007 at 03:05 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/vb-net-programming/842-network-connection-checking-using-api.html
Posted By For Type Date
Digg / Programming / Upcoming This thread Refback 07-20-2007 05:19 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
automatic error checking amansundar PHP Programming 1 09-25-2007 08:31 AM
Checking the server disk space Murali Server Management 6 08-29-2007 07:19 AM
What is the difference between internet connection and GPRS or mobile net connection? sathishkumar Computer Hardware 2 08-11-2007 04:16 AM
upload status checking in javascript venkatbi PHP Programming 0 07-20-2007 08:18 AM
List of Link Checking Tools vadivelanvaidyanathan Testing Tools 0 03-21-2007 11:00 PM


All times are GMT -7. The time now is 01:53 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0