📄 如何检测是否modem与网络相连.txt
字号:
在 检 测 之 后 , 应 该 使 用 PortOpen=False关 闭 Modem。
如 何 你 要 是 想 判 断 用 户 是 否 与 Internet相 连 也 可 以 这 样 做 :
将 下 面 的 代 码 加 入 一 个 模 块 :
Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias _
"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long
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
你 就 可 以 使 用 ActiveConnection进 行 检 测 了 。
Private Sub Command1_Click()
If ActiveConnection = True Then
Call MsgBox("You have an active connection.", vbInformation)
Else
Call MsgBox("You have no active connections.", vbInformation)
End If
End Sub
另 外 , 如 果 安 装 了 IE 4.0以 上 版 本 , 也 可 以 使 用 InternetGetConnectedState函 数 判 断 是 否 与 Internet相 连 , 这 种 方 法 不 仅 可 以 判 断 拨 号 方 式 , 也 可 以 判 断 通 过 局 域 网 连 接 。
<END>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -