Is my PC connected to the Internet?

I want to know how can i know (via VB) if my computer is connected to the Internet.

Thanks in advance.
pin_plunderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tommy_boyCommented:
This should really have been a 100 point question..

'Detecting and Internet connection

'Declarations
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long
Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long

Declare Function RegOpenKey Lib "advapi32.dll" Alias _
"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long
               
'Form/Module Code
Public Function ActiveConnection() As Boolean
Dim hKey As Long
Dim lpSubKey As String
Dim phkResult As Long
Dim lpValueName As String
Dim lpReserved As Long
Dim lpType As Long
Dim lpData As Long
Dim lpcbData As Long
ActiveConnection = False
lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, _
phkResult)

If ReturnCode = ERROR_SUCCESS Then
    hKey = phkResult
    lpValueName = "Remote Connection"
    lpReserved = APINULL
    lpType = APINULL
    lpData = APINULL
    lpcbData = APINULL
    ReturnCode = RegQueryValueEx(hKey, lpValueName, _
    lpReserved, lpType, ByVal lpData, lpcbData)
    lpcbData = Len(lpData)
    ReturnCode = RegQueryValueEx(hKey, lpValueName, _
    lpReserved, lpType, lpData, lpcbData)
   
    If ReturnCode = ERROR_SUCCESS Then
        If lpData = 0 Then
            ActiveConnection = False
        Else
            ActiveConnection = True
        End If
    End If
               
RegCloseKey (hKey)
End If

End Function
               
'Function Code:

If ActiveConnection = True then
    Call MsgBox("You have an active connection.",vbInformation)
Else
    Call MsgBox("You have no active connections.", vbInformation)
End If  

Downloading a Web Page

You must have a Winsock control loaded into the project. This code assumes the control is called Winsock1. There also must be a text box on the form which is called txtWebPage.
First, connect to the remote computer using the following code:
Winsock1.RemoteHost = "jelsoft.com"
Winsock1.RemotePort = 80
Winsock1.Connect      
In the Winsock1.Connect event, place the following code to download the web page.
Dim strCommand as String
Dim strWebPage as String
strWebPage = "http://www.jelsoft.com/index.html"
strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
strCommand = strCommand + "Accept: */*" + vbCrLf
strCommand = strCommand + "Accept: text/html" + vbCrLf
strCommand = strCommand + vbCrLf
Winsock1.SendData strCommand      
The Winsock control will attempt to download the page. When is receives some data from the server, it will trigger the DataArrival event.
Dim webData As String
Winsock1.GetData webData, vbString
TxtWebPage.Text = TxtWebPage.Text + webData      
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pin_plunderAuthor Commented:
yeah... i know.. sorry for the points, but as i have just registered i've got few points.

gonna check code. then i'll tell you if you get the points or not.
thanks
0
pin_plunderAuthor Commented:
good answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.