在VB程序中怎样挂断拨号网络

王朝厨房·作者佚名  2007-01-04
宽屏版  字体: |||超大  

北京理工大学 李海

---- 要想控制拨号网络,就要使用Remote Access Service (RAS) API,这个API最早是在Windows for Workgroup 3.11中出现的,现在它已经成为Win32 API的一个组成部分。挂断拨号网络的函数叫RasHangUp,这个函数的功能和用法都很简单,它只有一个参数,就是要挂断的拨号网络连接的句柄。我们可以利用RasEnumConnections获得当前系统所有RAS连接(通常我们的系统在一个时刻只使用一个拨号网络连接),利用这个函数我们就可以得到RasHangUp所需的句柄了。不过RasEnumConnections函数在Windows 95和Windows NT下的使用略有不同,限于篇幅我们只给出在Windows 95下调用该函数的例子。读者可以从Win32 API的手册找到所有相关函数的详细介绍,不过VB的WIN32API.TXT中没有包括RAS API所需的声明语句,我们在下面给出解决本问题所需要的函数和结构声明。

---- 为了运行下面这个例子,首先需要建立一个窗体,在窗体上放置一个按钮,然后输入以下语句:

Option Explicit

Private Declare Function RasHangUp Lib

"RasApi32.DLL" Alias "RasHangUpA"

(ByVal hRasConn As Long) As Long

Private Declare Function RasEnumConnections

Lib "RasApi32.DLL" Alias "RasEnumConnectionsA"

(lprasconn As Any, lpcb As Long,

lpcConnections As Long) As Long

Const RAS95_MaxEntryName = 256

Const RAS95_MaxDeviceName = 128

Const RAS_MaxDeviceType = 16

Private Type RASCONN95

注释:set dwsize to 412

dwSize As Long

hRasConn As Long

szEntryName(RAS95_MaxEntryName) As Byte

szDeviceType(RAS_MaxDeviceType) As Byte

szDeviceName(RAS95_MaxDeviceName) As Byte

End Type

Private Sub Command1_Click()

Dim lngRetCode As Long

Dim lpcb As Long

Dim lpcConnections As Long

Dim intArraySize As Integer

Dim intLooper As Integer

ReDim lprasconn95(intArraySize) As RASCONN95

lprasconn95(0).dwSize = 412

lpcb = 256 * lprasconn95(0).dwSize

lngRetCode = RasEnumConnections

(lprasconn95(0), lpcb, lpcConnections)

If lngRetCode = 0 Then

If lpcConnections > 0 Then

For intLooper = 0 To lpcConnections - 1

RasHangUp lprasconn95(intLooper).hRasConn

Next intLooper

Else

MsgBox "没有拨号网络连接!", vbInformation

End If

End If

End Sub

---- 运行时,按下按钮就可以断开拨号网络的连接。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有