聲明以下函數變量常量:
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->