鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 网站制作教程 > vbs > >

怎样用VB得知系统当前是否处于internet链结状态

来源:互联网 作者:佚名 时间:2015-10-15 13:40
声明以下函数变量常量: DeclareFunctionRegCloseKeyLib"advapi32.dll"(ByValhKeyAsLong)AsLong DeclareFunctionRegQueryValueExLib"advapi32.dll"Alias"RegQueryValueExA"(ByValhKeyAsLong,ByVallpValueNameAsString,ByVallPReservedAsLong,lpTypeAsLong,lp
声明以下函数变量常量:
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->

网友评论
<