Skip to content

Instantly share code, notes, and snippets.

@simply-coded
Last active July 16, 2025 03:16
Show Gist options
  • Save simply-coded/510c789d575e6bff12a3d455c2f5d1e9 to your computer and use it in GitHub Desktop.
Save simply-coded/510c789d575e6bff12a3d455c2f5d1e9 to your computer and use it in GitHub Desktop.

Revisions

  1. simply-coded revised this gist Oct 1, 2016. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion Disable_Wi-Fi.vbs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    Option Explicit
    Dim interface, interfaceName, interfaceTarget, available, verb

    'Pick the Interface Name you want to disable/enable
    'Pick the Interface Name you want to disable
    interfaceName = "Wi-Fi"
    'Find available Names by running this script or in cmd
    '>> netsh interface show interface [enter]
    2 changes: 1 addition & 1 deletion Enable_Wi-Fi.vbs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    Option Explicit
    Dim interface, interfaceName, interfaceTarget, available, verb

    'Pick the Interface Name you want to disable/enable
    'Pick the Interface Name you want to enable
    interfaceName = "Wi-Fi"
    'Find available Names by running this script or in cmd
    '>> netsh interface show interface [enter]
  2. simply-coded revised this gist Oct 1, 2016. No changes.
  3. simply-coded created this gist Oct 1, 2016.
    58 changes: 58 additions & 0 deletions Disable_Wi-Fi.vbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    '************************
    '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/enable
    interfaceName = "Wi-Fi"
    'Find available Names by running this script or in cmd
    '>> netsh interface show interface [enter]

    '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

    If Not success Then
    MsgBox "Already disabled : """ & interfaceName & """", vbInformation
    End If
    58 changes: 58 additions & 0 deletions Enable_Wi-Fi.vbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    '***********************
    'Name: Enable 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/enable
    interfaceName = "Wi-Fi"
    'Find available Names by running this script or in cmd
    '>> netsh interface show interface [enter]

    '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 = "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 enabled : """ & interfaceName & """", vbInformation
    End If
    55 changes: 55 additions & 0 deletions Toggle_Wi-Fi.vbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    '***********************
    'Name: Toggle 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/enable
    interfaceName = "Wi-Fi"
    'Find available Names by running this script or in cmd
    '>> netsh interface show interface [enter]

    '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
    For Each verb In interfaceTarget.Verbs
    If verb.Name = "En&able" Then
    verb.DoIt
    WScript.Sleep 1000
    MsgBox "Enabled: """ & interfaceName & """", vbInformation
    ElseIf verb.Name = "Disa&ble" Then
    verb.DoIt
    WScript.Sleep 1000
    MsgBox "Disabled: """ & interfaceName & """", vbInformation
    End If
    Next