'****
'Name: Disable Connection
'Author: Jeremy England
'Company: SimplyCoded
'Date: 10/01/2016
'****
Option Explicit
Dim interface, interfaceName, interfaceTarget, available, verb'Pick the Interface Name you want to disable
interfaceName ="A"
'Find available Names by running this script or in cmd
'>> netsh interface show interface
'Set up required objects
Dim objApp : Set objApp = CreateObject("Shell.Application")
Dim objFolder : Set objFolder = objApp.Namespace(&H31&).Self.GetFolder
'Check if Network Connections folder exists
If objFolder Is Nothing Then
MsgBox "Network Connections folder not found. Check the location: ""C:\Windows\System32\ncpa.cpl""", vbCritical
WScript.Quit
End If
'Make sure interface exists
Set interfaceTarget = Nothing
'Interface exists
For Each interface In objFolder.Items
If LCase(interface.Name) = LCase(interfaceName) Then
Set interfaceTarget = interface
End If
available = available & interface.Name & vbLf
Next
'Interface Doesn't exist
If interfaceTarget Is Nothing Then
MsgBox "Interface Name: """ & interfaceName & """ not found. " &_
"Available Interface Names: " & vbLf & vbLf & available, vbCritical
WScript.Quit
End If
'Interface Enable / Disable
Dim success : success = False
For Each verb In interfaceTarget.Verbs
If verb.Name = "Disa&ble" Then
verb.DoIt
WScript.Sleep 1000
'MsgBox "Disabled: """ & interfaceName & """", vbInformation
'success = True
Exit For
End If
Next
WScript.Sleep 3000
'Dim success : success = False
For Each verb In interfaceTarget.Verbs
If verb.Name = "En&able" Then
verb.DoIt
WScript.Sleep 1000
'MsgBox "Enabled: """ & interfaceName & """", vbInformation
'success = True
Exit For
End If
Next
If Not success Then
'MsgBox "Already disabled : """ & interfaceName & """", vbInformation
End If