用户
购买联系
定制软件
智动博客助手
智动终级刷IP工具
首页
首页
/
编程技术
拨号、断网、枚举连接名称,判断是否在线、连
时间:
2010年04月12日
点击:
372
(转贴:魏滔序原创)
Option
Explicit
'
拨号/断网
Private
Declare
Function InternetDial()
Function
InternetDial
Lib
"
wininet.dll
"
(
ByVal
hwndParent
As
Long
,
ByVal
lpszConnectoid
As
String
,
ByVal
dwFlags
As
Long
, lpdwConnection
As
Long
,
ByVal
dwReserved
As
Long
)
As
Long
Private
Declare
Function InternetHangUp()
Function
InternetHangUp
Lib
"
wininet.dll
"
(
ByVal
dwConnection
As
Long
,
ByVal
dwReserved
As
Long
)
As
Long
Private
Declare
Function InternetAutodial()
Function
InternetAutodial
Lib
"
wininet.dll
"
(
ByVal
dwFlags
As
Long
,
ByVal
dwReserved
As
Long
)
As
Long
Private
Declare
Function InternetAutodialHangup()
Function
InternetAutodialHangup
Lib
"
wininet.dll
"
(
ByVal
dwReserved
As
Long
)
As
Long
Private
Const
INTERNET_DIALSTATE_DISCONNECTED
=
1
Private
Const
INTERNET_AUTODIAL_FORCE_ONLINE
=
1
Private
Const
INTERNET_AUTODIAL_FORCE_UNATTENDED
=
2
Private
Const
INTERNET_DIAL_UNATTENDED
=
&
H8000
Private
Handle
As
Long
'
网络状态
Private
Declare
Function InternetGetConnectedStateEx()
Function
InternetGetConnectedStateEx
Lib
"
wininet.dll
"
Alias
"
InternetGetConnectedStateExA
"
(
ByRef
lpdwFlags
As
Long
,
ByVal
lpszConnectionName
As
String
,
ByVal
dwNameLen
As
Long
,
ByVal
dwReserved
As
Long
)
As
Long
Private
Declare
Function InternetGetConnectedState()
Function
InternetGetConnectedState
Lib
"
wininet.dll
"
(
ByRef
dwFlags
As
Long
,
ByVal
dwReserved
As
Long
)
As
Long
Private
Const
INTERNET_CONNECTION_MODEM
As
Long
=
&
H1
'
本系统使用调制解调器与因特网相连
Private
Const
INTERNET_CONNECTION_LAN
As
Long
=
&
H2
'
本系统通过LAN与因特网相连
Private
Const
INTERNET_CONNECTION_PROXY
As
Long
=
&
H4
'
本系统使用proxy代理服务器与因特网相连
Private
Const
INTERNET_CONNECTION_MODEM_BUSY
As
Long
=
&
H8
'
未使用
Private
Const
INTERNET_RAS_INSTALLED
As
Long
=
&
H10
Private
Const
INTERNET_CONNECTION_OFFLINE
As
Long
=
&
H20
Private
Const
INTERNET_CONNECTION_CONFIGURED
As
Long
=
&
H40
'
枚举网络连接
Private
Const
RAS_MaxDeviceType
=
16
Private
Const
RAS95_MaxDeviceName
=
128
Private
Const
RAS95_MaxEntryName
=
256
Private
Type RASCONN95
dwSize
As
Long
hRasConn
As
Long
szEntryName(RAS95_MaxEntryName)
As
Byte
szDeviceType(RAS_MaxDeviceType)
As
Byte
szDeviceName(RAS95_MaxDeviceName)
As
Byte
End
Type
Private
Type RASENTRYNAME95
dwSize
As
Long
szEntryName(RAS95_MaxEntryName)
As
Byte
End
Type
Private
Declare
Function RasEnumConnections()
Function
RasEnumConnections
Lib
"
rasapi32.dll
"
Alias
"
RasEnumConnectionsA
"
(lprasconn
As
Any, lpcb
As
Long
, lpcConnections
As
Long
)
As
Long
Private
Declare
Function RasEnumEntries()
Function
RasEnumEntries
Lib
"
rasapi32.dll
"
Alias
"
RasEnumEntriesA
"
(
ByVal
reserved
As
String
,
ByVal
lpszPhonebook
As
String
, lprasentryname
As
Any, lpcb
As
Long
, lpcEntries
As
Long
)
As
Long
Private
Declare
Function RasHangUp()
Function
RasHangUp
Lib
"
rasapi32.dll
"
Alias
"
RasHangUpA
"
(
ByVal
hRasConn
As
Long
)
As
Long
'
拨号
Public
Function DialUp()
Function
DialUp(LinkName
As
String
)
As
Boolean
InternetDial
0
, LinkName, INTERNET_AUTODIAL_FORCE_UNATTENDED, Handle,
0
DialUp
=
(Handle
<>
0
)
End
Function '()
Function
'
断网
Public
Sub HangUp()
Sub
HangUp()
If
Handle
<>
0
Then
InternetHangUp Handle,
0
Handle
=
0
End
If
End
Sub '()
Sub
'
枚举网络连接
Public
Sub EnumConnectName()
Sub
EnumConnectName(Value()
As
String
)
Dim
s
As
Long
, l
As
Long
, ln
As
Long
, a
As
String
ReDim
r(
255
)
As
RASENTRYNAME95
r(
0
).dwSize
=
264
s
=
256
*
r(
0
).dwSize
l
=
RasEnumEntries(vbNullString, vbNullString, r(
0
), s, ln)
ReDim
Value(ln
-
1
)
For
l
=
0
To
ln
-
1
a
=
StrConv
(r(l).szEntryName(), vbUnicode)
Value(l)
=
Left
$(a$,
InStr
(a$,
Chr
$(
0
))
-
1
)
Next
End
Sub '()
Sub
'
判断是否在线
Public
Function Online()
Function
Online()
As
Boolean
Online
=
InternetGetConnectedState(
0
&
,
0
&
)
End
Function '()
Function
'
判断是否在线并返回连接方式
Public
Property Get()
Property
Get
OnlineOfLinkName(LinkName
As
String
)
As
Boolean
LinkName
=
Space
$(
128
)
OnlineOfLinkName
=
InternetGetConnectedStateEx(
0
, LinkName,
128
,
0
&
)
End
Property '()
Property
'
如果是通过LAN的连接,则返回True
Public
Function IsNetConnectViaLAN()
Function
IsNetConnectViaLAN()
As
Boolean
Dim
dwFlags
As
Long
Call
InternetGetConnectedState(dwFlags,
0
&
)
IsNetConnectViaLAN
=
dwFlags
And
INTERNET_CONNECTION_LAN
End
Function '()
Function
'
如果是通过调制解调器的连接,则返回True
Public
Function IsNetConnectViaModem()
Function
IsNetConnectViaModem()
As
Boolean
Dim
dwFlags
As
Long
Call
InternetGetConnectedState(dwFlags,
0
&
)
IsNetConnectViaModem
=
dwFlags
And
INTERNET_CONNECTION_MODEM
End
Function '()
Function
'
如果是通过Proxy代理服务器的连接,则返回True
Public
Function IsNetConnectViaProxy()
Function
IsNetConnectViaProxy()
As
Boolean
Dim
dwFlags
As
Long
Call
InternetGetConnectedState(dwFlags,
0
&
)
IsNetConnectViaProxy
=
dwFlags
And
INTERNET_CONNECTION_PROXY
End
Function '()
Function
'
如果已安装了RAS,则返回True
Public
Function IsNetRASInstalled()
Function
IsNetRASInstalled()
As
Boolean
Dim
dwFlags
As
Long
Call
InternetGetConnectedState(dwFlags,
0
&
)
IsNetRASInstalled
=
dwFlags
And
INTERNET_RAS_INSTALLED
End
Function '()
Function
'
返回当前网络状态信息字符串
Public
Function GetNetConnectString()
Function
GetNetConnectString()
As
String
Dim
dwFlags
As
Long
Dim
msg
As
String
If
InternetGetConnectedState(dwFlags,
0
&
)
Then
If
dwFlags
And
INTERNET_CONNECTION_CONFIGURED
Then
msg
=
msg
&
"
系统配置了网络连接
"
&
vbCrLf
End
If
If
dwFlags
And
INTERNET_CONNECTION_LAN
Then
msg
=
msg
&
"
系统通过局域网与因特网相连接
"
End
If
If
dwFlags
And
INTERNET_CONNECTION_PROXY
Then
msg
=
msg
&
"
并使用了Proxy代理服务
"
Else
: msg
=
msg
&
"
.
"
End
If
If
dwFlags
And
INTERNET_CONNECTION_MODEM
Then
msg
=
msg
&
"
系统使用调制解调器与因特网相连接
"
End
If
If
dwFlags
And
INTERNET_CONNECTION_OFFLINE
Then
msg
=
msg
&
"
系统当前处于离线状态
"
End
If
If
dwFlags
And
INTERNET_CONNECTION_MODEM_BUSY
Then
msg
=
msg
&
"
系统的调制解调器未连接到因特网
"
End
If
If
dwFlags
And
INTERNET_RAS_INSTALLED
Then
msg
=
msg
&
"
本系统安装了远程访问服务
"
End
If
Else
msg
=
"
当前未与因特网相连
"
End
If
GetNetConnectString
=
msg
End
Function ()
Function
更多DotNet好文章www.zdexe.com
赞助商链接
热门内容
Navicat 中读取MYSQL数据显中文乱码问题解决方法
Proguard混淆提示类重复(Duplicate zip entry等提示)
phpstorm不安装apache就可以本地测试PHP
C# ListView随窗体大小自动改变列宽
MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
C#出现A generic error occurred in GDI+问题分析与解决
C#如何将控件设置为透明效果
钩子(HOOK)函数教程(一)
C#时常需要调用C++DLL问题详解
目录未找到或者无法访问:“ ./data/template”的解决
Sqlite:一个SQL搞定,记录存在不插入或者替换数据
C#实现自定义外观并可拖动和改变大小的窗口
相关内容
Android 实现模拟按键,模拟操作
Sqlite:一个SQL搞定,记录存在不插入或者替换数据
Nginx伪静态配置和常用Rewrite伪静态规则集锦
MQTT协议简要介绍
Navicat 中读取MYSQL数据显中文乱码问题解决方法
phpstorm不安装apache就可以本地测试PHP
Proguard混淆提示类重复(Duplicate zip entry等提示)
Android权限设置总汇
C#出现A generic error occurred in GDI+问题分析与解决
SQLite 简介
用PHP操作sqlite数据库
用JAVA操作SQLite
我们的产品
智动终极刷IP工具
智动博客助手
智动邮件搜索
联系我们
copyright © 2008 - 2021
智动软件
关于我们
联系我们
代理合作
投诉建议
常见问题
常用组件下载