下載點
http://www.ziddu.com/download/14543606/Net_Open_Close.rar.html
Imports System.Runtime.InteropServices.GCHandle
Imports System.Runtime.InteropServices.GCHandleType
Public Class Form1
Private Const NetConnect As Integer = &H31
Private Function ExcNetLinkMenu(ByVal AdapterName As String, ByVal MenuName As String) As Boolean
On Error Resume Next
Dim Shell32 As Object
Dim lNameLenPtr As Integer
Dim lNameLen As Integer
Dim Handle As System.Runtime.InteropServices.GCHandle
Dim GCHandle As System.Runtime.InteropServices.GCHandleType
Handle = System.Runtime.InteropServices.GCHandle.Alloc("NetConnection", Pinned)
lNameLenPtr = Handle.AddrOfPinnedObject.ToInt32
Dim mShell As Shell32.Shell = New Shell32.Shell
Dim NetConnection As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetConnectionItem As New Shell32.ShellFolderItem
Dim verb As Shell32.FolderItemVerb
NetConnection = mShell.NameSpace(49)
If lNameLenPtr = 0 Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
Dim flag As Boolean
flag = False
For Each FolderItem In NetConnection.Items
If FolderItem.Name = AdapterName Then
NetConnectionItem = FolderItem
flag = True
Exit For
End If
Next FolderItem
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
For Each verb In NetConnectionItem.Verbs
If verb.Name = MenuName Then
flag = True
verb.DoIt()
ExcNetLinkMenu = True
GoTo exitfunction
End If
Next verb
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
exitfunction:
mShell = Nothing
NetConnection = Nothing
FolderItem = Nothing
NetConnectionItem = Nothing
verb = Nothing
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'把區域連線 6 換成你 網路名字
Dim blnRelust As Boolean
blnRelust = ExcNetLinkMenu("區域連線 6", "停用(&B)")
If blnRelust Then
MsgBox("停用成功")
Else
blnRelust = ExcNetLinkMenu("區域連線 6", "禁用(&B)")
End If
If blnRelust Then
MsgBox("停用成功")
Else
MsgBox("停用失败")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim blnRelust As Boolean
blnRelust = ExcNetLinkMenu("區域連線 6", "啟用(&A)")
If blnRelust Then
MsgBox("启用成功")
Else
MsgBox("启用失败")
End If
End Sub
End Class
請先 登入 以發表留言。