程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> 怎樣用VB得知系統當前是否處於internet鏈結狀態

怎樣用VB得知系統當前是否處於internet鏈結狀態

編輯:VB綜合教程
聲明以下函數變量常量:
  DeclareFunctionRegCloseKeyLib"advapi32.dll"(ByValhKeyAsLong)AsLong
  
  DeclareFunctionRegQueryValueExLib"advapi32.dll"Alias"RegQueryValueExA"(ByValhKeyAsLong,ByVallpValueNameAsString,ByVallpReservedAsLong,lpTypeAsLong,lpDataAsAny,lpcbDataAsLong)AsLong
  
  DeclareFunctionRegOpenKeyLib"advapi32.dll"Alias"RegOpenKeyA"(ByValhKeyAsLong,ByVallpSubKeyAsString,phkResultAsLong)AsLong
  
  PublicConstERROR_SUCCESS=0&
  
  PublicConstAPINULL=0&
  
  PublicConstHKEY_LOCAL_MACHINE=&H80000002
  
  PublicReturnCodeAsLong
  
  代碼:
  
  PublicFunctionActiveConnection()AsBoolean
  
  DimhKeyAsLong
  
  DimlpSubKeyAsString
  
  DimphkResultAsLong
  
  DimlpValueNameAsString
  
  DimlpReservedAsLong
  
  DimlpTypeAsLong
  
  DimlpDataAsLong
  
  DimlpcbDataAsLong
  
  ActiveConnection=False
  
  lpSubKey="SystemCurrentControlSetServicesRemoteAccess"
  
  ReturnCode=RegOpenKey(HKEY_LOCAL_MACHINE,lpSubKey,phkResult)
  
  IfReturnCode=ERROR_SUCCESSThen
  
  hKey=phkResult
  
  lpValueName="RemoteConnection"
  
  lpReserved=APINULL
  
  lpType=APINULL
  
  lpData=APINULL
  
  lpcbData=APINULL
  
  ReturnCode=RegQueryValueEx(hKey,lpValueName,lpReserved,lpType,lpData,lpcbData)
  
  lpcbData=Len(lpData)
  
  ReturnCode=ReturnCode=RegQueryValueEx(hKey,lpValueName,lpReserved,lpType,lpData,lpcbData)
  
  IfReturnCode=ERROR_SUCCESSThen
  
  IflpData=0Then
  
  ActiveConnection=False
  
  Else
  
  ActiveConnection=True
  
  EndIf
  
  EndIf
  
  RegCloseKey(hKey)
  
  EndIf
  
  EndFunction
  
  下面是使用以上代碼的例子:
  
  IfActiveConnection=Truethen
  
  CallMsgBox("現在處於鏈結狀態。",vbInformation)
  
  Else
  
  CallMsgBox("現在處於斷開狀態。",vbInformation)
  
  EndIf->

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved