-
Feb 10th, 2013, 07:51 PM
#1
Thread Starter
Banned
check if internet is connected or not
add this in module
Code:
Option Explicit
Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As Long) As Long
Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceType = 16
Public Const RAS95_MaxDeviceName = 32
Public Type RASCONN95
dwSize As Long
hRasCon As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Function IsConnected() As Boolean
Dim TRasCon(255) As RASCONN95
Dim lg As Long
Dim lpcon As Long
Dim RetVal As Long
Dim Tstatus As RASCONNSTATUS95
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
MsgBox "Error " & Err & " Has Occured!", vbOKOnly + vbCritical, "Error!"
Exit Function
End If
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If
End Function
Code:
Private Sub Command2_Click()
Text1.Text = IsConnected
End Sub
-
Feb 10th, 2013, 09:46 PM
#2
Re: check if internet is connected or not
What operating systems does the code work under?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Feb 11th, 2013, 07:21 AM
#3
Thread Starter
Banned
Re: check if internet is connected or not
i have windows xp sp2 not tested on others
-
Feb 11th, 2013, 08:24 AM
#4
Re: check if internet is connected or not
The magic number &H2000 should really be &H2000& since it is a long/Enum. It is RASCS_Connected, which is set to RASCS_DONE, which is a constant &H2000&.
Magic numbers should be avoided.
Worse yet, this code is useless unless you are using Dial-Up Networking (Remote Access Service). And it only checks your first dial connection (you might have several and it ignores the others).
-
Feb 12th, 2013, 05:09 AM
#5
Thread Starter
Banned
Re: check if internet is connected or not
with respect il like to say it isnt usless like i am on dial up its usefull for me, so there are multi million people out there also will have same connection as me and will use this i tested this and works as i wanted
-
Mar 14th, 2013, 03:05 PM
#6
Re: check if internet is connected or not
Here's one I found somewhere. Don't know if it's useful or not
Code:
Public gWebConnection As Boolean
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Public Function CheckInternetConnection() As Boolean
Dim aux As String * 255
Dim r As Long
r = InternetGetConnectedStateEx(r, aux, 254, 0)
If r = 1 Then
CheckInternetConnection = True
Else
CheckInternetConnection = False
End If
End Function
Private Sub Command1_Click()
If (CheckInternetConnection = True) Then
MsgBox "Your connected"
Else
MsgBox "Your not connected"
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|