Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Verificar conexão com Internet

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
pedrobb
Colaborador
Colaborador
Mensagens: 74
Registrado em: Qua Jul 25, 2012 12:42 pm
Localização: Montes Claros-MG

Verificar conexão com Internet

Mensagem por pedrobb »

Para verificar conexão com a Internet, Tentei usar a função abaixo:

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

Sub TesteConexaoInternet()
Dim Ret As Long
Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
If Ret = 1 Then
MsgBox "Você está conectado a Internet via " & sConnType, vbInformation
Else
MsgBox "Você não está conectado a Internet", vbInformation
End If
End Sub

Mas uso Windows 7 - 64 bits. e dá erro pedindo atualização para 64 bits.
Alguem pode ajudar?
Grato,
Pedro


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


CavalheiroCambará
Acabou de chegar
Acabou de chegar
Mensagens: 1
Registrado em: Sáb Fev 18, 2017 9:45 am

Re: Verificar conexão com Internet

Mensagem por CavalheiroCambará »

Este é o código. Personalize a vontade no Sub main().

Option Explicit

#If Win64 Then
Public Flg As LongPtr
Public Declare PtrSafe Function InternetGetConnectedState _
Lib "wininet.dll" (lpdwFlags As LongPtr, _
ByVal dwReserved As Long) As Boolean
#Else
Public Flg As Long
Public Declare Function InternetGetConnectedState _
Lib "wininet.dll" (lpdwFlags As Long, _
ByVal dwReserved As Long) As Boolean
#End If

Private Const INTERNET_CONNECTION_MODEM As Long = &H1
Private Const INTERNET_CONNECTION_LAN As Long = &H2
Private Const INTERNET_CONNECTION_PROXY As Long = &H4
Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20

Function IsInternetConnected() As Boolean
Dim R As Long

R = InternetGetConnectedState(Flg, 0&)

If Flg >= INTERNET_CONNECTION_OFFLINE Then
Debug.Print "INTERNET_CONNECTION_OFFLINE"
End If

If CBool(R) Then
IsInternetConnected = True
Else
IsInternetConnected = False
End If
End Function

Sub main()
Dim mssg As String
If IsInternetConnected Then
mssg = "Connected"
Else
mssg = "Not connected"
End If
MsgBox mssg
End Sub


pedrobb
Colaborador
Colaborador
Mensagens: 74
Registrado em: Qua Jul 25, 2012 12:42 pm
Localização: Montes Claros-MG

Re: Verificar conexão com Internet

Mensagem por pedrobb »

CavalheiroCambará,
Perfeito.
Muito Obrigado!
Pedro


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder