-
Mar 7th, 2009, 03:18 PM
#1
Thread Starter
Junior Member
[RESOLVED] Check if have internet VB6
Hello again. Please, I need you to help me on this one, if you can. I have a button, and what I want to do is that when I press that button, the program check if the machine has any connection to the internet. If so, to display a msgbox saying (it has), and vieversa.
Thanks you
-
Mar 7th, 2009, 03:31 PM
#2
Re: Check if have internet VB6
Code:
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
Dim sConnType As String * 255
Private Sub Command1_Click()
If (CheckInternetConnection = True) Then
MsgBox "We have an active Internet connection!"
Else
MsgBox "We don't have an active Internet connection!"
End If
End Sub
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 7th, 2009, 03:56 PM
#3
Re: Check if have internet VB6
internetconnectedstate will return true if there is a valid LAN connection, regardless of whether there is a WAN connection, so it is not a reliable test
ideally you need to ping your isp server, or download a small file from somewhere, for a more reliable test
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 7th, 2009, 04:06 PM
#4
Re: Check if have internet VB6
Yes you are right pete... Ok try this (I like your ping idea... I tried it with Yahoo and it worked )
Code:
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
(ByVal hInet As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, _
ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As _
String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
Private Sub Command1_Click()
Dim hInet As Long, hUrl As Long, Flags As Long, url As Variant
hInet = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0&)
If hInet Then
Flags = INTERNET_FLAG_KEEP_CONNECTION Or INTERNET_FLAG_NO_CACHE_WRITE _
Or INTERNET_FLAG_RELOAD
hUrl = InternetOpenUrl(hInet, "http://www.yahoo.com", _
vbNullString, 0, Flags, 0)
If hUrl Then
MsgBox "Your computer is connected to Internet", _
vbInformation, "Checking connection"
Call InternetCloseHandle(hUrl)
Else
MsgBox "Your computer is not connected to Internet", _
vbInformation, "Checking connection"
End If
End If
Call InternetCloseHandle(hInet)
End Sub
Last edited by Siddharth Rout; Mar 7th, 2009 at 04:12 PM.
Reason: Spell Check
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 7th, 2009, 04:24 PM
#5
Thread Starter
Junior Member
Re: Check if have internet VB6
Well, really thanks you on this one guys. I have tested it with my internet on and it worked, later I changed the ping url to iwegweiugbwi (or something) and it said i wasn't connected.
The only problem is if yahoo server turn inactive... jeje
Thanks you
-
Mar 7th, 2009, 06:09 PM
#6
Re: [RESOLVED] Check if have internet VB6
The only problem is if yahoo server turn inactive... jeje
that is why i suggested pinging your isp server, if it is inactive then you probably have no connection anyway
presumably if your internet is disconnected then internetopen will return 0, without actually going to any site
Last edited by westconn1; Mar 7th, 2009 at 06:13 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|