top
Loading...
VB中檢測是否連網
p>利用WIN95中的注冊表建植,在注冊表的HKEY-LOCAL-MACHINESystemCurrentControlSetServicesRemoteAcces下,當計算機連上因特網時,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="SystemCurrentControlSetServicesRemoteAccess"

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

作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗