把这个函数生成exe文件
Private Sub StartConnection()
Dim X
X = Shell("rundll32.exe rnaui.dll,RnaDial " & "_连接的名称_", 1)
DoEvents
SendKeys "{enter}", True
DoEvents
End Sub
Private Sub Command1_Click()
'首先,从工程 -引用 对话框中,找到并添加Microsoft Shell Controls And Automation
On Error Resume Next
Dim AdapterName As String
AdapterName = "本地连接 2" '修改成你要控制的网络连接的名字
Dim mShell As New Shell32.Shell
Dim NetConnection As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetConnectionItem As ShellFolderItem
Dim verb As Shell32.FolderItemVerb
Set NetConnection = mShell.NameSpace(49) '这个49是我找出来的,有了它就可以避免遍历控制面板
If ObjPtr(NetConnection) = 0 Then
MsgBox "error"
Exit Sub
End If
Dim flag As Boolean
flag = False
For Each FolderItem In NetConnection.Items
If FolderItem.Name = AdapterName Then
Set NetConnectionItem = FolderItem
flag = True
Exit For
End If
Next
If flag = False Then
MsgBox "error"
Exit Sub
End If
For Each verb In NetConnectionItem.Verbs
'Print verb.Name
If verb.Name = "创建快捷方式(&S)" Then
verb.DoIt
Exit For
End If
Next
End Sub