[200分 200元酬谢] 请高手帮忙用 vb.net 做一个小程序,实现 adsl 自动断线,自动拨号上网。 RMB 酬谢!
我们公司需要用到一套程序,用 vb.net 2005/2008 开发,现在想实现一个小的功能模块,公司出 200 块预算找人做一下。
只需要实现 adsl 自动断线自动拨号上网即可。
需要在 windows xp,windows vista 下调试通过。
开发工具 vb.net 2005/2008 (如果是 C# 的话也可以,就是麻烦转一下代码)
由于这类程序网上搜索下有很多现成的代码,只需要组合下即可,一般懂的人2,3个小时调试时间就能搞定了。
如果您有兴趣可以联系我。我通过支付宝先付钱给您,您调试通过后再发给我即可。
我的联系方式
QQ 55840
TEL 13817328000
P.S. ADSL 账号和密码需要保存在XML 文件中
<Adsl Auto="1">
<UserName>ad12345678</UserName>
<Password>1234567890</Password>
</Adsl>
[最优解释]
连接和断开都搞定了
Imports System.Runtime.InteropServices
Public Class Form1
Public Const RAS_MaxEntryName As Int32 = 256
Public Const RAS_MaxPhoneNumber As Int32 = 128
Public Const RAS_MaxCallbackNumber As Int32 = 128
Public Const RAS_MaxUserName As Int32 = 256
Public Const RAS_MaxPassword As Int32 = 256
Public Const RAS_MaxDomain As Int32 = 15
Public Const RAS_MaxDeviceType As Int32 = 16
Public Const RAS_MaxDeviceName As Int32 = 128
Public WINVER501 As Integer
Public Structure GUID
Public Data1 As UInteger
Public Data2 As UShort
Public Data3 As UShort
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public data4() As Byte
End Structure
Public Structure LUID
Public LowPart As Integer
Public HighPart As Integer
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Public Structure RASDIALPARAMS
Public Size As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxEntryName + 1)> Public EntryName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxPhoneNumber + 1)> Public PhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxCallbackNumber + 1)> Public CallBackNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxUserName + 1)> Public UserName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxPassword + 1)> Public Password As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxDomain + 1)> Public Domain As String
Public dwSubEntry As Integer
Public dwCallbackId As UInt32
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure RASCONN
Public dwSize As Integer
Public hrasconn As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxEntryName + 1)> Public szEntryName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxDeviceType + 1)> Public szDeviceType As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxDeviceName + 1)> Public szDeviceName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> Public szPhonebook As String
Public dwSubEntry As Integer
Public guidEntry As GUID
#If (WINVER501) Then
Public dwFlags As Integer
Public luid As LUID
#End If
End Structure
Public Declare Auto Function RasGetEntryDialParams Lib "rasapi32.dll" (ByVal PhoneBook As String, ByRef DialParams As RASDIALPARAMS, ByRef Password As Int32) As Int32
Public Declare Unicode Function RasDial Lib "rasapi32.dll" Alias "RasDialW" (ByVal RasDialExtensions As Int32, ByVal PhoneBook As String, ByRef DialParams As RASDIALPARAMS, ByVal NotifierType As Int32, ByVal Notifier As Int32, ByRef hRasConnection As Int32) As Int32
Public Declare Auto Function RasEnumConnections Lib "rasapi32.dll" (ByRef lprasconn As RASCONN, ByRef lpcb As Integer, ByRef lpcConnections As Integer) As Integer
Public Declare Auto Function RasHangUp Lib "rasapi32.dll" (ByVal hrasconn As IntPtr) As Integer
Private Function Connect(ByVal EntryName As String) As Integer
Dim hRASHandle As IntPtr
Dim params As New RASDIALPARAMS
Dim rtn As Int32, bResult As Boolean = False
params.Size = Marshal.SizeOf(params)
params.EntryName = EntryName
Dim bFlag As Int32 = 0
rtn = RasGetEntryDialParams(vbNullString, params, bFlag)
If rtn = 0 Then
Return RasDial(Nothing, vbNullString, params, 0, Nothing, hRASHandle) ' returns 632 for some reason...
End If
End Function
Private Function Disconnect() As Integer
Dim RasCon As New RASCONN
Dim lbcp As Integer
Dim lpconnection As Integer
RasCon.dwSize = Marshal.SizeOf(GetType(RASCONN))
lbcp = RasCon.dwSize
RasEnumConnections(RasCon, lbcp, lpconnection)
RasHangUp(RasCon.hrasconn)
End Function
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Disconnect()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Connect("ADSL")
End Sub
End Class
Imports System.Runtime.InteropServices
Public Class Form1
Public Const RAS_MaxEntryName As Int32 = 256
Public Const RAS_MaxPhoneNumber As Int32 = 128
Public Const RAS_MaxCallbackNumber As Int32 = 128
Public Const RAS_MaxUserName As Int32 = 256
Public Const RAS_MaxPassword As Int32 = 256
Public Const RAS_MaxDomain As Int32 = 15
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure RASDIALPARAMS
Public Size As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxEntryName + 1)> Public EntryName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxPhoneNumber + 1)> Public PhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxCallbackNumber + 1)> Public CallBackNumber As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxUserName + 1)> Public UserName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxPassword + 1)> Public Password As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MaxDomain + 1)> Public Domain As String
Public dwSubEntry As Integer
Public dwCallbackId As UInt32
End Structure
Public Declare Auto Function RasGetEntryDialParams Lib "rasapi32.dll" ( _
ByVal PhoneBook As String, _
ByRef DialParams As RASDIALPARAMS, _
ByRef Password As Int32) As Int32
Public Declare Unicode Function RasDial Lib "rasapi32.dll" Alias "RasDialW" ( _
ByVal RasDialExtensions As Int32, _
ByVal PhoneBook As String, _
ByRef DialParams As RASDIALPARAMS, _
ByVal NotifierType As Int32, _
ByVal Notifier As Int32, _
ByRef hRasConnection As Int32) As Int32
Private Function GetRasDialParams(ByVal EntryName As String) As Integer
Dim hRASHandle As IntPtr
Dim params As New RASDIALPARAMS
Dim rtn As Int32, bResult As Boolean = False
params.Size = Marshal.SizeOf(params)
params.EntryName = EntryName
params.UserName = "administrator"
params.Password = "08255868879"
Dim bFlag As Int32 = 0
'rtn = RasGetEntryDialParams(vbNullString, params, bFlag)
'Me.Text = params.Password
If rtn = 0 Then
Return RasDial(Nothing, vbNullString, params, 0, Nothing, hRASHandle) ' returns 632 for some reason...
End If
End Function
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Text = GetRasDialParams("adsl")
End Sub
End Class