|
|
|
|
|
Dicas
|
|
Visual Basic (Internet)
|
|
|
Título da Dica: Verificando se o Computador está Conectado à Internet
|
|
|
|
Postada em 14/8/2000 por Webmaster
webmaster@vbweb.com.br
'No módulo:
Private Const ERROR_SUCCESS = 0& Private Const APINULL = 0& Private Const HKEY_LOCAL_MACHINE = &H80000002 Private ReturnCode As Long
Private Declare Function RegCloseKey Lib _ "advapi32.dll" (ByVal hKey As Long) _ As Long Private Declare Function RegOpenKey Lib _ "advapi32.dll" Alias "RegOpenKeyA" _ (ByVal hKey As Long, ByVal _ lpSubKey As String, phkResult As _ Long) As Long Private 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
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
'P/ chamar a função, no evento que você quizer: If ActiveConnection Then 'Está conectado Else 'NÃO Está conectado End If
|
|
|
|
|