声明以下函数变量常量:
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->