インターネット接続状況の取得(T) <TOP>
InternetGetConnectedState ローカルシステムのインターネット接続状況を取得します。
'================================================================
'= インターネット接続状況の取得(T)
'= (InternetGetConnectedState.bas)
'================================================================
#include "Windows.bi"
' ローカルシステムのインターネット接続状況を返す
Declare Function Api_InternetGetConnectedState& Lib "wininet" Alias "InternetGetConnectedState" (ByRef lpdwFlags&, ByVal dwReserved&)
#define INTERNET_CONNECTION_OFFLINE &H20 'オフライン
#define INTERNET_CONNECTION_CONFIGURED &H40 '接続の設定を完了
#define INTERNET_CONNECTION_LAN &H2 '接続にLANを使用
#define INTERNET_CONNECTION_MODEM &H1 '接続にモデムを使用
#define INTERNET_CONNECTION_MODEM_BUSY &H8 'ビジー
#define INTERNET_CONNECTION_PROXY &H4 '接続にプロキシ・サーバーを使用
#define INTERNET_RAS_INSTALLED &H10 'RAS(Remote Access Service)がインストールされている
Var Shared Text(11) As Object
Var Shared Button1 As Object
For i = 0 To 11
Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1)))
Text(i).SetFontSize 12
Next
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 12
'================================================================
'=
'================================================================
Declare Function NetConnectByLAN() As Integer
Function NetConnectByLAN() As Integer
Var dwflags As Long
Var Ret As Long
Ret = Api_InternetGetConnectedState(dwflags, 0)
NetConnectByLAN = dwflags And INTERNET_CONNECTION_LAN
End Function
'================================================================
'=
'================================================================
Declare Function NetConnectByModem() As Integer
Function NetConnectByModem() As Integer
Var dwflags As Long
Var Ret As Long
Ret = Api_InternetGetConnectedState(dwflags, 0)
NetConnectByModem = dwflags And INTERNET_CONNECTION_MODEM
End Function
'================================================================
'=
'================================================================
Declare Function NetConnectByProxy() As Integer
Function NetConnectByProxy() As Integer
Var dwflags As Long
Var Ret As Long
Ret = Api_InternetGetConnectedState(dwflags, 0)
NetConnectByProxy = dwflags And INTERNET_CONNECTION_PROXY
End Function
'================================================================
'=
'================================================================
Declare Function NetConnectOnline() As Integer
Function NetConnectOnline() As Integer
NetConnectOnline = Api_InternetGetConnectedState(0, 0)
End Function
'================================================================
'=
'================================================================
Declare Function NetRASInstalled() As Integer
Function NetRASInstalled() As Integer
Var dwflags As Long
Var Ret As Long
Ret = Api_InternetGetConnectedState(dwflags, 0)
NetRASInstalled = dwflags And INTERNET_RAS_INSTALLED
End Function
'================================================================
'=
'================================================================
Declare Function GetNetConnectString() As String
Function GetNetConnectString() As String
Var dwflags As Long
Var MSG As String
Var CrLf As String
CrLf = Chr$(13, 10)
If Api_InternetGetConnectedState(dwflags, 0) Then
If dwflags And INTERNET_CONNECTION_CONFIGURED Then
MSG = MSG & "ネットワークに接続。" & CrLf
End If
If dwflags And INTERNET_CONNECTION_LAN Then
MSG = MSG & "ローカルシステムはLANを経由してインターネットと接続。"
End If
If dwflags And INTERNET_CONNECTION_PROXY Then
MSG = MSG & "プロクシーサーバーを使用。"
Else
MSG = MSG
End If
If dwflags And INTERNET_CONNECTION_MODEM Then
MSG = MSG & "ローカルシステムはMODEMを経由してインターネットと接続。"
End If
If dwflags And INTERNET_CONNECTION_OFFLINE Then
MSG = MSG & "オフライン接続。"
End If
If dwflags And INTERNET_CONNECTION_MODEM_BUSY Then
MSG = MSG & "モデムはビジー状態です。"
End If
If dwflags And INTERNET_RAS_INSTALLED Then
MSG = MSG & "RAS(リモートアクセスサービス)はこのシステムにインストールされています。"
End If
Else
MSG = "現在インターネットに接続していません。"
End If
GetNetConnectString = MSG
End Function
'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
If NetConnectByLAN() = 0 Then Text(6).SetWindowText "False" Else Text(6).SetWindowText "True"
If NetConnectByModem() = 0 Then Text(7).SetWindowText "False" Else Text(7).SetWindowText "True"
If NetConnectByProxy() = 0 Then Text(8).SetWindowText "False" Else Text(8).SetWindowText "True"
If NetConnectOnline() = 0 Then Text(9).SetWindowText "False" Else Text(9).SetWindowText "True"
If NetRASInstalled() = 0 Then Text(10).SetWindowText "False" Else Text(10).SetWindowText "True"
Text(11).SetWindowText GetNetConnectString()
End Sub
'================================================================
'=
'================================================================
While 1
WaitEvent
Wend
Stop
End