当前位置:首页 > 网络编程 > 软件语言 > .NET > 如何取得预设宽带连接PPPOE拨接帐号

如何取得预设宽带连接PPPOE拨接帐号

点击次数:37 次 发布日期:2008-11-06 08:05:20 作者:源代码网
源代码网推荐
广告载入中

源代码网整理以下<< VB.NET >> 写法 1

源代码网整理以下 

源代码网整理以下" 匯入名称空间

软件开发网 www.mscto.com

源代码网整理以下Imports System

源代码网整理以下Imports System.Text

源代码网整理以下Imports Microsoft.Win32

源代码网整理以下Imports System.Runtime.InteropServices

源代码网整理以下 

源代码网整理以下Public Class Form1

源代码网整理以下 

软件开发网 www.mscto.com

源代码网整理以下    Private Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click

源代码网整理以下        Dim ras As New RAS_API

源代码网整理以下        MessageBox.Show(ras.GetDefDialAcc) " 取得预设拨接帐号

源代码网整理以下    End Sub

源代码网整理以下 

源代码网整理以下End Class

源代码网整理以下 

源代码网整理以下Public Class RAS_API

源代码网整理以下 

源代码网整理以下    " API 宣告

源代码网整理以下    Private Declare Function RasGetEntryDialParamsA Lib "RasAPI32.dll" _

源代码网整理以下        (ByVal PB As String, ByRef DialPara As Byte, ByRef Pswd As Integer) As Integer

源代码网整理以下 

源代码网整理以下    " 由登录档取得预设连线名称

源代码网整理以下    Public Function GetDefDialAcc() As String

源代码网整理以下        Dim k As String = "SoftwareMicrosoftRAS AutoDialDefault"

源代码网整理以下        GetDefDialAcc = Registry.LocalMachine.OpenSubKey(k).GetValue("DefaultInternet")

软件开发网 www.mscto.com

源代码网整理以下        Return IIf(GetDefDialAcc.Length > 0, GetDialAcc(GetDefDialAcc), "")

源代码网整理以下    End Function

源代码网整理以下  软件开发网 www.mscto.com

源代码网整理以下    " 根据预设连线取得拨接帐号名称

源代码网整理以下    Public Function GetDialAcc(ByVal Entry As String) As String

源代码网整理以下        GetDialAcc = ""

源代码网整理以下        Dim b(1060) As Byte

源代码网整理以下        CpMm(1060, b, 0, 4)

源代码网整理以下        CpMm(Encoding.Default.GetBytes(Entry), b, 4, 256)

源代码网整理以下        If RasGetEntryDialParamsA(vbNullString, b(0), 1) = 0 Then

源代码网整理以下            Return Encoding.Default.GetString(b, 519, 257).TrimEnd(Chr(0))

源代码网整理以下        End If

源代码网整理以下    End Function

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下    " CopyMemory

软件开发网 www.mscto.com

源代码网整理以下    Private Sub CpMm(ByRef s As Object, ByRef d As Object, ByVal b As Integer, ByVal l As Integer)

源代码网整理以下        Marshal.Copy(GCHandle.Alloc(s, GCHandleType.Pinned).AddrOfPinnedObject, d, b, l)

软件开发网 www.mscto.com

源代码网整理以下    End Sub

源代码网整理以下  软件开发网 www.mscto.com

源代码网整理以下End Class

源代码网整理以下 

源代码网整理以下 

源代码网整理以下" ================================================================

源代码网整理以下 

源代码网整理以下 

源代码网整理以下<< VB.NET >> 写法 2

源代码网整理以下 

源代码网整理以下" 匯入名称空间

软件开发网 www.mscto.com

源代码网整理以下Imports System

源代码网整理以下Imports System.Text

源代码网整理以下Imports Microsoft.Win32

源代码网整理以下Imports System.Runtime.InteropServices

源代码网整理以下 

源代码网整理以下Public Class Form2

源代码网整理以下 

源代码网整理以下    Private Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click

源代码网整理以下        Dim r As New RAS

源代码网整理以下        MessageBox.Show(r.GetDefDialAcc) " 取得预设拨接帐号

源代码网整理以下    End Sub

源代码网整理以下 

源代码网整理以下End Class

源代码网整理以下 

源代码网整理以下Public Class RAS

源代码网整理以下 

源代码网整理以下    " 宣告结构

源代码网整理以下    <StructLayout(LayoutKind.Sequential)> _

源代码网整理以下    Public Structure RasDialParas

软件开发网 www.mscto.com

源代码网整理以下        Public dwSize As Integer

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public EntryName As String

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public PhoneNumber As String 软件开发网 www.mscto.com

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public CallbackNumber As String

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public UserName As String

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public Password As String

源代码网整理以下        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> Public Domain As String

源代码网整理以下        Public dwSubEntry As UInt32

源代码网整理以下        Public dwCallbackId As IntPtr 软件开发网 www.mscto.com

源代码网整理以下    End Structure

源代码网整理以下 

源代码网整理以下    " API 宣告

源代码网整理以下    Private Declare Function RasGetEntryDialParamsA Lib "RasAPI32.dll" _

软件开发网 www.mscto.com

源代码网整理以下        (ByVal Phonebook As String, ByRef RasDialPara As RasDialParas, ByRef PswdR As Integer) As Integer

源代码网整理以下 

源代码网整理以下    " 由登录档取得预设连线名称

源代码网整理以下    Public Function GetDefDialAcc() As String

源代码网整理以下        Dim k As String = "SoftwareMicrosoftRAS AutoDialDefault" 软件开发网 www.mscto.com

源代码网整理以下        GetDefDialAcc = Registry.LocalMachine.OpenSubKey(k).GetValue("DefaultInternet")

源代码网整理以下        Return IIf(GetDefDialAcc.Length > 0, GetDialAcc(GetDefDialAcc), "")

源代码网整理以下    End Function

源代码网整理以下 

源代码网整理以下    " 根据预设连线取得拨接帐号名称

源代码网整理以下    Public Function GetDialAcc(ByVal Entry As String) As String

软件开发网 www.mscto.com

源代码网整理以下        GetDialAcc = ""

源代码网整理以下        Dim rdp As New RasDialParas

源代码网整理以下        rdp.dwSize = 1060 软件开发网 www.mscto.com

源代码网整理以下        rdp.EntryName = Entry & New String(Chr(0), 257 - Entry.Length)

源代码网整理以下        If RasGetEntryDialParamsA(vbNullString, rdp, 1) = 0 Then Return rdp.UserName

源代码网整理以下    End Function

源代码网整理以下 

源代码网整理以下End Class

源代码网整理以下 

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下" ================================================================

源代码网整理以下 

源代码网整理以下 

源代码网整理以下<< VB6 >> 写法 1

源代码网整理以下 

源代码网整理以下" API 宣告

源代码网整理以下Private Declare Function RasGetEntryDialParamsA Lib "RasAPI32.dll" _

源代码网整理以下    (ByVal Phonebook As String, RasDialPara As Byte, _

源代码网整理以下    PswdRet As Long) As Long

源代码网整理以下 

源代码网整理以下Private Declare Sub RtlMoveMemory Lib "Kernel32" _

源代码网整理以下    (Destination As Any, Source As Any, ByVal Length As Long)

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下Private Sub Command1_Click()

软件开发网 www.mscto.com

源代码网整理以下    MsgBox GetDefDialAcc " 取得预设拨接帐号

源代码网整理以下End Sub

软件开发网 www.mscto.com

源代码网整理以下 

软件开发网 www.mscto.com

源代码网整理以下" 由登录档取得预设连线名称

源代码网整理以下Private Function GetDefDialAcc() As String

源代码网整理以下    Dim k As String

源代码网整理以下    k = "HKLMSOFTWAREMicrosoftRAS AutoDialDefaultDefaultInternet"

源代码网整理以下    GetDefDialAcc = CreateObject("WScript.Shell").RegRead(k)

软件开发网 www.mscto.com

源代码网整理以下    If GetDefDialAcc <> "" Then GetDefDialAcc = GetDialAcc(GetDefDialAcc)

源代码网整理以下End Function

源代码网整理以下 

源代码网整理以下" 根据预设连线取得拨接帐号名称

源代码网整理以下Private Function GetDialAcc(Entry As String) As String 软件开发网 www.mscto.com

源代码网整理以下    Dim bytAry(1059) As Byte

源代码网整理以下    RtlMoveMemory bytAry(0), 1060&, 4&

源代码网整理以下    Str2Byt bytAry(4), Entry, 256

源代码网整理以下    If RasGetEntryDialParamsA(vbNullString, bytAry(0), 0&) = 0 Then

源代码网整理以下        Byt2Str GetDialAcc, bytAry(519), 257

源代码网整理以下    End If

源代码网整理以下End Function

源代码网整理以下 

源代码网整理以下" 位元阵列转字串

源代码网整理以下Private Sub Byt2Str(ByRef C2S As String, ByRef Byt As Byte, ByRef MxL As Long)

源代码网整理以下   C2S = String(MxL + 1, 0)

源代码网整理以下   RtlMoveMemory ByVal C2S, Byt, MxL

源代码网整理以下   C2S = Left(C2S, InStr(C2S, Chr(0)) - 1)

源代码网整理以下End Sub 软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下" 字串转位元阵列

源代码网整理以下Private Sub Str2Byt(ByRef Byt As Byte, ByRef S2C As String, ByRef MxL As Long)

源代码网整理以下    Dim lngLen As Long

源代码网整理以下    lngLen = Len(S2C)

源代码网整理以下    If lngLen > 0 Then RtlMoveMemory Byt, ByVal S2C, IIf(lngLen > MxL, MxL, lngLen)

源代码网整理以下End Sub

源代码网整理以下 

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下" ================================================================

源代码网整理以下 

源代码网整理以下 

源代码网整理以下<< VB6 >> 写法 2

源代码网整理以下 

源代码网整理以下" 宣告自订型态

源代码网整理以下Private Type RasDialPara

源代码网整理以下    dwSize As Long

源代码网整理以下    EntryName(256) As Byte

源代码网整理以下    PhoneNumber(128) As Byte

源代码网整理以下    CallbackNumber(128) As Byte

软件开发网 www.mscto.com

源代码网整理以下    UserName(256) As Byte

源代码网整理以下    Password(256) As Byte

源代码网整理以下    Domain(12) As Byte

源代码网整理以下End Type

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下" API 宣告

源代码网整理以下Private Declare Function RasGetEntryDialParamsA Lib "rasapi32.dll" _

源代码网整理以下    (ByVal Phonebook As String, ByRef RasDialPara As RasDialPara, _

源代码网整理以下    ByRef PswdRet As Long) As Long

源代码网整理以下 

源代码网整理以下Private Declare Sub RtlMoveMemory Lib "Kernel32" _

源代码网整理以下    (Destination As Any, Source As Any, ByVal Length As Long)

源代码网整理以下 

源代码网整理以下Private Sub Command1_Click()

源代码网整理以下    MsgBox GetDefDialAcc " 取得预设拨接帐号

源代码网整理以下End Sub

源代码网整理以下 

源代码网整理以下 " 由登录档取得预设连线名称

源代码网整理以下Private Function GetDefDialAcc() As String

源代码网整理以下    Dim k As String

源代码网整理以下    k = "HKLMSOFTWAREMicrosoftRAS AutoDialDefaultDefaultInternet"

源代码网整理以下    GetDefDialAcc = CreateObject("WScript.Shell").RegRead(k)

源代码网整理以下    If GetDefDialAcc <> "" Then GetDefDialAcc = GetDialAcc(GetDefDialAcc)

源代码网整理以下End Function

源代码网整理以下  软件开发网 www.mscto.com

源代码网整理以下" 根据预设连线取得拨接帐号名称

源代码网整理以下Private Function GetDialAcc(Entry As String) As String

源代码网整理以下    Dim EntryName(256) As Byte 软件开发网 www.mscto.com

源代码网整理以下    Dim rdp As RasDialPara

源代码网整理以下    rdp.dwSize = 1060

源代码网整理以下    Str2Byt rdp.EntryName(0), Entry, Len(Entry)

源代码网整理以下    If RasGetEntryDialParamsA(vbNullString, rdp, 0) = 0 Then

源代码网整理以下        GetDialAcc = Chg2Unicode(rdp.UserName)

软件开发网 www.mscto.com

源代码网整理以下    End If

源代码网整理以下End Function

源代码网整理以下 

源代码网整理以下" 位元阵列转字串

源代码网整理以下Private Function Chg2Unicode(byt() As Byte) As String

源代码网整理以下    Chg2Unicode = StrConv(byt, vbUnicode)

源代码网整理以下    Chg2Unicode = Left(Chg2Unicode, InStr(Chg2Unicode, Chr(0)) - 1)

源代码网整理以下End Function

源代码网整理以下 

源代码网整理以下" 字串转位元阵列

源代码网整理以下Private Sub Str2Byt(ByRef byt As Byte, ByRef S2C As String, ByRef MxL As Long)

源代码网整理以下    Dim lngLen As Long

源代码网整理以下    lngLen = Len(S2C)

源代码网整理以下    If lngLen > 0 Then RtlMoveMemory byt, ByVal S2C, IIf(lngLen > MxL, MxL, lngLen)

源代码网整理以下End Sub


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华