# Re: 如何测知网路是否连线?

Posted by JC on June 07, 1999 at 11:55:35:

In Reply to: Re: 如何测知网路是否连线? posted by Honey on June 06, 1999 at 23:44:40:

: :提供你以下程式
: 在form上贴上一个command1就好了
: Option Explicit
: Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
: hKey As Long) As Long
: Private Declare Function RegOpenKey Lib "advapi32.dll" Alias _
: "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
: String, phkResult As Long) As Long
: Private 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

: Const ERROR_SUCCESS = 0&
: Const RAS_MAXENTRYNAME As Integer = 256
: Const RAS_MAXDEVICETYPE As Integer = 16
: Const RAS_MAXDEVICENAME As Integer = 128
: Const RAS_RASCONNSIZE As Integer = 412
: Const APINULL = 0&
: Const HKEY_LOCAL_MACHINE = &H80000002
: Private Type RasEntryName
: dwSize As Long
: szEntryName(RAS_MAXENTRYNAME) As Byte
: End Type

: Private Type RasConn
: dwSize As Long
: hRasConn As Long
: szEntryName(RAS_MAXENTRYNAME) As Byte
: szDeviceType(RAS_MAXDEVICETYPE) As Byte
: szDeviceName(RAS_MAXDEVICENAME) As Byte
: End Type

: Dim ReturnCode 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)
: '/*取得HKEY_LOCAL_MACHINE底下 _
: System\CurrentControlSet\Services\RemoteAccess _
: phkResult是传回SubKey的hKey*/

: If ReturnCode = ERROR_SUCCESS Then
: '/*RegOpenKey若执行成功会传回0*/
: hKey = phkResult '/*hKey*/
: 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)
: '/*lpValueName:名称 _
: lpReserved:保留参数 _
: lpType:资料类别 _
: lpData:传回资料 _
: lpcbData:资料长度*/
:
: If ReturnCode = ERROR_SUCCESS Then
: '/*RegQueryValueEx执行成功会传回零*/
: If lpData = 0 Then
: ActiveConnection = False
: '/*未取得连线*/
: Else
: ActiveConnection = True
: '/*取得连线*/
: End If
: End If
:
: RegCloseKey (hKey)
: '/*关闭*/
: End If
: End Function

: Private Sub Command1_Click()
: Call ActiveConnection
: If ActiveConnection = True Then
: MsgBox "有连线", vbInformation
: Else
: MsgBox "没有连线", vbInformation
: End If
: End Sub

可否告诉我哪里有显示连线传输速度的程式码？

Follow Ups: