VB에서 웹사이트의 연결전에 사전 가능여부를 확인시에 사용하십시요...
Option Explicit
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Const strURL As String = "http://www.excellove.com"
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long
'================================================================================
' Function : GetInetConnect
' DateTime : 2007-08-12 05:20
' Author : 서은아빠 (http://cafe.naver.com/xlsvba/11)
' Purpose : 인터넷 연결가능여부와 연결 가능시 지정 웹페이지의 연결상태를 리턴.
' Param : strURLname - 해당 URL(인수값도 던진다)
' Return : -1 -> 인터넷 연결불가, 0 -> 지정사이트 접속불가 혹은 존재치 안음, 1 -> 정상연결
'================================================================================
Private Function GetInetConnect(ByRef strURLname As String) As Long
If InternetAttemptConnect(0) = 0 Then
If InternetCheckConnection(strURLname, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
GetInetConnect = 0
Else
GetInetConnect = 1
End If
Else
GetInetConnect = -1
End If
End Function
'## 실행
Sub Test()
Dim lngRet As Long
lngRet = GetInetConnect(strURL)
Select Case lngRet
Case -1: MsgBox "인터넷 연결이 불가능한 상태입니다.", vbInformation
Case 0: MsgBox strURL & "이 존재하지 않거나 해당사이트의 연결이 불가한 상태입니다.", vbInformation
Case 1: MsgBox strURL & "와 연결이 가능합니다.", vbInformation
End Select
End Sub
Option Explicit
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Const strURL As String = "http://www.excellove.com"
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long
'================================================================================
' Function : GetInetConnect
' DateTime : 2007-08-12 05:20
' Author : 서은아빠 (http://cafe.naver.com/xlsvba/11)
' Purpose : 인터넷 연결가능여부와 연결 가능시 지정 웹페이지의 연결상태를 리턴.
' Param : strURLname - 해당 URL(인수값도 던진다)
' Return : -1 -> 인터넷 연결불가, 0 -> 지정사이트 접속불가 혹은 존재치 안음, 1 -> 정상연결
'================================================================================
Private Function GetInetConnect(ByRef strURLname As String) As Long
If InternetAttemptConnect(0) = 0 Then
If InternetCheckConnection(strURLname, FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
GetInetConnect = 0
Else
GetInetConnect = 1
End If
Else
GetInetConnect = -1
End If
End Function
'## 실행
Sub Test()
Dim lngRet As Long
lngRet = GetInetConnect(strURL)
Select Case lngRet
Case -1: MsgBox "인터넷 연결이 불가능한 상태입니다.", vbInformation
Case 0: MsgBox strURL & "이 존재하지 않거나 해당사이트의 연결이 불가한 상태입니다.", vbInformation
Case 1: MsgBox strURL & "와 연결이 가능합니다.", vbInformation
End Select
End Sub
'ETC*' 카테고리의 다른 글
USB메모리의 파일시스템을 FAT32에서 NTFS로 간편하게 변환 (0) | 2009.09.16 |
---|---|
- (0) | 2009.04.27 |
C# 무료동영상강의 (0) | 2009.03.19 |
WININET 정리 - 2(HTTP) (0) | 2008.12.09 |
계산기 : KB, MB, GB, TB, PB 환산 Convert (0) | 2008.09.22 |