怎样用VB得知系统当前是否处于internet链结状态
2006-02-27 21:13:03 来源:WEB开发网核心提示:声明以下函数变量常量:DeclareFunctionRegCloseKeyLib"advapi32.dll"(ByValhKeyAsLong)AsLongDeclareFunctionRegQueryValueExLib"advapi32.dll"Alias"RegQu
声明以下函数变量常量:
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="System\CurrentControlSet\Services\Remoteaccess"
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->
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="System\CurrentControlSet\Services\Remoteaccess"
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->
[]
更多精彩
赞助商链接