怎样用脚本创建网络连接

DawnPine 2006-03-11 07:39:10
比如说我要创建一个ADSL网络连接
已知ADSL的 用户名/密码

用手工操作创建这个连接是很容易的事
但如何用脚本完成同样的工作?
用VBS+WMI可以吗? 可我没找到实现的方法 :(
...全文
217 点赞 收藏 15
写回复
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
BookSirSwordsMan 2006-03-19
关注中……
回复
DawnPine 2006-03-19
1. 试验成功了, 新建连接在
控制面板-网络连接
里,和平常手动创建的连接在同一位置

2. 将 .dwfOptions = 1024262928
这一句改为
.dwfOptions = 1006830352
可跳过密码确认窗口

3. 在没有资料的情况下一点点地摸索这些属性实在太困难了
谁有RAS的属性、方法等方面的资料?
或者给个链接也行,最好是中文。

4. 怎样为刚建立的这个连接创建一个快捷方式并放在桌面上?
关于这个问题我放了200分在这个帖子里:

http://community.csdn.net/Expert/topic/4624/4624019.xml?temp=.4635431
回复
vbcrack 2006-03-17
显示建设成功了
但不知道是建立在哪里的
回复
DawnPine 2006-03-17
果然是绿豆
超级的那种

赶明儿回家试试
有试验成功的也来报个喜呀
回复
supergreenbean 2006-03-15
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Type RASIPADDR
a As Byte
b As Byte
c As Byte
d As Byte
End Type

Private Type RASENTRY
dwSize As Long
dwfOptions As Long
dwCountryID As Long
dwCountryCode As Long
szAreaCode(10) As Byte
szLocalPhoneNumber(128) As Byte
dwAlternateOffset As Long
ipaddr As RASIPADDR
ipaddrDns As RASIPADDR
ipaddrDnsAlt As RASIPADDR
ipaddrWins As RASIPADDR
ipaddrWinsAlt As RASIPADDR
dwFrameSize As Long
dwfNetProtocols As Long
dwFramingProtocol As Long
szScript(259) As Byte
szAutodialDll(259) As Byte
szAutodialFunc(259) As Byte
szDeviceType(16) As Byte
szDeviceName(128) As Byte
szX25PadType(32) As Byte
szX25Address(200) As Byte
szX25Facilities(200) As Byte
szX25UserData(200) As Byte
dwChannels As Long
dwReserved1 As Long
dwReserved2 As Long
dwSubEntries As Long
dwDialMode As Long
dwDialExtraPercent As Long
dwDialExtraSampleSeconds As Long
dwHangUpExtraPercent As Long
dwHangUpExtraSampleSeconds As Long
dwIdleDisconnectSeconds As Long
dwType As Long
dwEncryptionType As Long
dwCustomAuthKey As Long
guidId As GUID
szCustomDialDll(259) As Byte
dwVpnStrategy As Long
dwfOptions2 As Long
dwfOptions3 As Long
szDnsSuffix(255) As Byte
dwTcpWindowSize As Long
szPrerequisitePbk(259) As Byte
szPrerequisiteEntry(256) As Byte
dwRedialCount As Long
dwRedialPause As Long
End Type

Private Type RASCREDENTIALS
dwSize As Long
dwMask As Long
szUserName(256) As Byte
szPassword(256) As Byte
szDomain(15) As Byte
End Type

Private Declare Function RasSetEntryProperties Lib "rasapi32" Alias "RasSetEntryPropertiesA" (ByVal lpszPhonebook As String, ByVal lpszEntry As String, lpRasEntry As RASENTRY, ByVal dwEntryInfoSize As Long, ByVal lpbDeviceInfo As Long, ByVal dwDeviceInfoSize As Long) As Long
Private Declare Function RasSetCredentials Lib "rasapi32" Alias "RasSetCredentialsA" (ByVal lpszPhonebook As String, ByVal lpszEntry As String, lpCredentials As RASCREDENTIALS, ByVal fClearCredentials As Long) As Long

Private Sub Form_Load()
Dim sEntryName As String, sUsername As String, sPassword As String

sEntryName = "宽带连接"
sUsername = "super"
sPassword = "greenbean"

If Create_PPPoE_Connection(sEntryName, sUsername, sPassword) Then
MsgBox "连接建立成功!"
Else
MsgBox "连接建立失败!"
End If
End Sub

Function Create_PPPoE_Connection(ByVal sEntryName As String, ByVal sUsername As String, ByVal sPassword As String) As Boolean
Create_PPPoE_Connection = False

Dim re As RASENTRY
Dim sDeviceName As String, sDeviceType As String
sDeviceName = "WAN 微型端口 (PPPOE)"
sDeviceType = "PPPoE"
With re
.dwSize = LenB(re)
.dwCountryCode = 86
.dwCountryID = 86
.dwDialExtraPercent = 75
.dwDialExtraSampleSeconds = 120
.dwDialMode = 1
.dwEncryptionType = 3
.dwfNetProtocols = 4
.dwfOptions = 1024262928
.dwfOptions2 = 367
.dwFramingProtocol = 1
.dwHangUpExtraPercent = 10
.dwHangUpExtraSampleSeconds = 120
.dwRedialCount = 3
.dwRedialPause = 60
.dwType = 5
CopyMemory .szDeviceName(0), ByVal sDeviceName, Len(sDeviceName)
CopyMemory .szDeviceType(0), ByVal sDeviceType, Len(sDeviceType)
End With

Dim rc As RASCREDENTIALS
With rc
.dwSize = LenB(rc)
.dwMask = 11
CopyMemory .szUserName(0), ByVal sUsername, Len(sUsername)
CopyMemory .szPassword(0), ByVal sPassword, Len(sPassword)
End With

Dim rtn As Long
If RasSetEntryProperties(vbNullString, sEntryName, re, LenB(re), 0, 0) = 0 Then
If RasSetCredentials(vbNullString, sEntryName, rc, 0) = 0 Then
Create_PPPoE_Connection = True
End If
End If
End Function



回复
vansoft 2006-03-15
可以,建過一個程序,控制連接上網的。
回复
lzw858 2006-03-14
就是啊,只要能建出来,用什么方法,软件都行
回复
DawnPine 2006-03-14
三颗星的都在帮顶

我们这帮穿三角裤的还指望who去?
得 就当散分好了 潜水的可以来冒个泡 不会有亏吃的 :-D
回复
supergreenbean 2006-03-14
用 RasSetEntryProperties 建立连接,再用RasSetEntryDialParams设用户名,密码
回复
ZOU_SEAFARER 2006-03-14
我也帮你顶,希望有高手来!楼主的问题真有水平呀,我的问题别人一看就知道!呵呵
回复
faysky2 2006-03-13
等待高手
回复
lzw858 2006-03-13
再顶啊
回复
lzw858 2006-03-13
我想知道怎样用VB建一个,一起顶
回复
帮顶
回复
DawnPine 2006-03-13
顶起
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7449

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告