利用WIN95中的注册表建植,在注册表的HKEY-LOCAL-MACHINE\System\CurrentControlSet\Services\RemoteAcces\下,当计算机连上因特网时,Remote
Connection的植为01 00 00 00,反之,为00 00 00 00,通过这一建植可判断是否连网。
1.建立新模块
Public Const ERROR-SUCCESS= 0&
Public Const APINULL= 0&
Public Const HKEY-LOCAL-MACHINE= &H80000002
Public ReturnCode As long
’声明API函数
RegCloseKey()
RegQueryValueEx()
’自定义函数
Public function ActiveConnection() As Boolean
Dim hKey As long
Dim lpSubKey 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,lpcbata)
lpcbData=Len(lpData)
ReturnCode=RegQueryValueEx(hKey,lpValueName,lpReserved,lpType,ByVal lpData,lpcbata)
If ReturnCode=ERROR-SUCCESS then
If lpData=0 then
ActiveConnection=False
Else
ActiveConnection=True
End If
End If
RegCloseKey(hKey)
End If
End funtion
2.新建窗体
Priate sub Command1_click()
If ActiveConnection=True then
MsgBox "OK!"
Else
MsgBox "ERROR!"
End If
End sub
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073










