PDA

View Full Version : فعال شدن هنگام اتصال به اینترنت



Microsoft.net
چهارشنبه 24 تیر 1383, 17:33 عصر
چطوری میشه وقتی به اینترنت وصل میشی و قطع می شی رو فهمید

sh
چهارشنبه 24 تیر 1383, 22:19 عصر
میتونی این کد رو استفاده کنی البته راههای دیگری هم داره


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 Form_Load()
Dim Ret As Long
Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
If Ret = 1 Then
MsgBox "You are connected to Internet via a " & sConnType, vbInformation
Else
MsgBox "You are not connected to internet", vbInformation
End If
End Sub


یا راه دیگه :


Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()

If InternetCheckConnection("http://www.barnamenevis.org/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to http://www.barnamenevis.org/ failed!", vbInformation
Else
MsgBox "Connection to http://www.barnamenevis.org/ succeeded!", vbInformation
End If
End Sub

علیرضا مداح
یک شنبه 28 تیر 1383, 09:02 صبح
سلام .
و روش دیگر ...
من همیشه از تابع زیر استفاده میکنم و خوب هم عمل میکنه .

Imports System.Runtime.InteropServices

<DllImport("wininet.dll")> _
Public Function InternetGetConnectedState( _
ByVal lpdwFlags As Integer, ByVal res As Integer) As Boolean
End Function

Public Function InternetConnectionExists() As Boolean
' Determines if there is a connection to the Internet.
' Note that InternetGetConnectedState cannot be considered
' 100% reliable. An issue can occur if an internet connection
' has never been configured, the function may return true, even
' though there is no internet connection.
'

Dim e As Integer = 0
Dim ret As Boolean = InternetGetConnectedState(e, 0)

Return ret

End Function