VB中检测是否连网

2008-04-09 04:39:59来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

  利用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,lpcba

ta)

lpcbData=Len(lpData)

ReturnCode=RegQueryValueEx(hKey,lpValueName,lpReserved,lpType,ByVal lpData,lpcba

ta)



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 sub

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ADO 在informix的 Addnew

下一篇:VB数据访问接口