| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4331 人关注过本帖
标题:[分享]用VB实现ADSL拨号和挂断(转)
取消只看楼主 加入收藏
leilei88
Rank: 2
来 自:青岛
等 级:论坛游民
帖 子:217
专家分:27
注 册:2008-3-30
结帖率:100%
收藏
 问题点数:0 回复次数:0 
[分享]用VB实现ADSL拨号和挂断(转)
1、第一个问题还要添上连接名(就是拨号连接的名字)
我这里有一个现成的代码,挺长的,能上网、断网、查看网络状态、查看连接数目,如果其它的不需要的话,自己看函数的名字,删了即可
把一下代码粘贴到模块中,在窗体某控件的时间中写:
程序代码:
Public Type RASCONN95
    dwSize As Long
    hRasConn As Long
    szEntryName(256) As Byte
    szDeviceType(16) As Byte
    szDeviceName(128) As Byte
End Type

Public Type RASCONNSTATUS95
    dwSize As Long
    RasConnState As Long
    dwError As Long
    szDeviceType(16) As Byte
    szDeviceName(128) As Byte
End Type

Public Type RASDIALPARAMS95
    dwSize As Long
    szEntryName(256) As Byte
    szPhoneNumber(128) As Byte
    szCallbackNumber(128) As Byte
    szUserName(256) As Byte
    szPassword(256) As Byte
    szDomain(15) As Byte
End Type

Public Declare Function RasGetConnectStatus Lib "RasApi32.DLL" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, ByVal lpString2 As String) As Long
Public Declare Function RasDial Lib "RasApi32.DLL" Alias "RasDialA" (lpRasDialExtensions As Any, ByVal lpszPhonebook As String, lprasdialparams As Any, ByVal dwNotifierType As Long, lpvNotifier As Long, lphRasConn As Long) As Long
Public Declare Function RasHangUp Lib "RasApi32.DLL" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Public Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias "RasEnumConnectionsA" (lprasconn As Any, lpcb As Long, lpcConnections As Long) As Long

Public Function AddConnection(strNewEntryName As String, strNewPhoneNumber As String, strNewCallbackNumber As String, strNewUsername As String, strNewPassword As String, strNewDomain As String) As Long
    Const APINULL = 0&
    Dim lngRetCode As Long
    Dim lngRetLstrcpy As Long
    Dim lngRetHangUp As Long
    Dim lprasdialparams As RASDIALPARAMS95
    On Error GoTo 10
    lprasdialparams.dwSize = 1052
    lngRetLstrcpy = lstrcpy(lprasdialparams.szEntryName(0), strNewEntryName)
    lngRetLstrcpy = lstrcpy(lprasdialparams.szPhoneNumber(0), strNewPhoneNumber)
    lngRetLstrcpy = lstrcpy(lprasdialparams.szCallbackNumber(0), strNewCallbackNumber)
    lngRetLstrcpy = lstrcpy(lprasdialparams.szUserName(0), strNewUsername)
    lngRetLstrcpy = lstrcpy(lprasdialparams.szPassword(0), strNewPassword)
    lngRetLstrcpy = lstrcpy(lprasdialparams.szDomain(0), strNewDomain)
    Screen.MousePointer = vbHourglass
    hRasConn = 0
    lngRetCode = RasDial(ByVal APINULL, vbNullString, lprasdialparams, APINULL, ByVal APINULL, hRasConn)
    Screen.MousePointer = vbDefault
    If lngRetCode Then
        lngRetHangUp = RasHangUp(hRasConn)
    End If
10
    AddConnection = lngRetCode
End Function

Public Function GetConnections() As Long
    Dim lngRetCode As Long
    Dim lpcb As Long
    Dim lpcConnections As Long
    Dim intArraySize As Long
    
    ReDim lprasconn95(intArraySize) As RASCONN95
    lprasconn95(0).dwSize = 412
    lpcb = 256 * lprasconn95(0).dwSize
    lngRetCode = RasEnumConnections(lprasconn95(0), lpcb, lpcConnections)
    GetConnections = lpcConnections
End Function

Public Function HangUpAll() As Boolean
    Dim lngRetCode As Long
    Dim lpcb As Long
    Dim lpcConnections As Long
    Dim intArraySize As Long
    Dim intLooper As Long
    
    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
            HangUpAll = False
            Exit Function
        End If
    End If
    HangUpAll = True
End Function
Public Function IsConnected() As Boolean
    Dim TRasCon(255) As RASCONN95
    Dim lg As Long
    Dim lpcon As Long
    Dim RetVal As Long
    Dim Tstatus As RASCONNSTATUS95
    TRasCon(0).dwSize = 412
    lg = 256 * TRasCon(0).dwSize
    RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
    Tstatus.dwSize = 160
    RetVal = RasGetConnectStatus(TRasCon(0).hRasConn, Tstatus)
    IsConnected = IIf(Tstatus.RasConnState = &H2000, True, False)
End Function


链接的时候在控件事件里写:
Dim recAdConn&
recAdConn = AddConnection("宽带连接", "", "", "登录账号", "登录密码", "")


2、查看当前IP
没有现成的代码,网上应该有的是吧!自己查一查
http://www.baidu.com/s?wd=VB+%B2%E9%BF%B4%B5%B1%C7%B0IP&cl=3

3、断网:第一个问题中已经说了,调用:
在控件事件中写
HangUpAll
完事

[[it] 本帖最后由 leilei88 于 2009-7-18 13:26 编辑 [/it]]
收到的鲜花
  • ak47my2009-07-18 10:34 送鲜花  41朵   附言:我很赞同
搜索更多相关主题的帖子: 分享 拨号 ADSL 
2009-07-18 09:46
快速回复:[分享]用VB实现ADSL拨号和挂断(转)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.083498 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved