Какие тормоза? Ты ReGet видел? Он же проверяет? Но каждую секунду я бы не стал. Проверяй раз в 2-3 секунды. Гарантирую, что тормозов не будет. Вот код. Выкинь лишние Declare, а то я из рабочей проги это взял - тут лишние есть. 'Working with registry declarations and constants Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Public 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 Const ERROR_SUCCESS = 0& Public Const APINULL = 0& Public Const HKEY_LOCAL_MACHINE = &H80000002 'Working with wininet.dll declarations and constants Public Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long 'Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long 'this function used with IE4 'Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long 'this function used with IE4 Public Const INTERNET_CONNECTION_MODEM = &H1& Public Const INTERNET_CONNECTION_LAN = &H2& Public Const INTERNET_CONNECTION_PROXY = &H4& Public Const INTERNET_RAS_INSTALLED = &H10& Public Const INTERNET_CONNECTION_OFFLINE = &H20& Public Const INTERNET_CONNECTION_CONFIGURED = &H40& 'Declares for direct ping Public 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 Public 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 Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0 Public Const INTERNET_FLAG_RELOAD = &H80000000 Public Const INTERNET_FLAG_KEEP_CONNECTION = &H400000 Public Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000 Public checkType As Integer Public remMsg(2) As String Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Const VER_PLATFORM_WIN32s = 0 Const VER_PLATFORM_WIN32_WINDOWS = 1 Const VER_PLATFORM_WIN32_NT = 2 Public Function CheckConnection(Optional ByRef ConnectionInfo As Long, Optional ByRef sConnectionName As String) As Boolean Dim dwFlags As Long Dim sNameBuf As String, msg As String Dim lPos As Long CheckConnection = False sNameBuf = String$(513, 0) If InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0& Then If dwFlags And INTERNET_CONNECTION_OFFLINE Then Else CheckConnection = True End If Else End If End Function
Ответить
|