HELP - Scritp to Turn Off (Disable) All Network then Script to Turn Back on

Discussion in 'Scripting' started by chrisgun, Sep 22, 2017.

  1. chrisgun

    chrisgun MDL Novice

    Feb 28, 2012
    35
    2
    0
    Hi I am looking for a 2 Script

    1. To Turn All Network Devices off - So computers if offline and cant connect to the Internet
    2. To Turn all Network Devices on again

    I am trying to run a program is after a fresh install - I have done this but it ideally need to be offline but after its installed then it enables again.

    Im able to create a script to run these programs but cant seem to see a script for this.
     
  2. TairikuOkami

    TairikuOkami MDL Expert

    Mar 15, 2014
    1,172
    1,052
    60
    Something like this?
    Code:
    wmic path win32_networkadapter where index=0 call disable
    wmic path win32_networkadapter where index=1 call disable
    wmic path win32_networkadapter where index=2 call disable
    wmic path win32_networkadapter where index=3 call disable
    wmic path win32_networkadapter where index=4 call disable
    wmic path win32_networkadapter where index=5 call disable
    Code:
    wmic path win32_networkadapter where index=0 call enable
    wmic path win32_networkadapter where index=1 call enable
    wmic path win32_networkadapter where index=2 call enable
    wmic path win32_networkadapter where index=3 call enable
    wmic path win32_networkadapter where index=4 call enable
    wmic path win32_networkadapter where index=5 call enable
     
  3. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    I have a nice little .vbs script to turn off the network..

    Code:
    '~ Toggle a SPECIFIED NIC on or off
    Option Explicit
    
    Const NETWORK_CONNECTIONS = &H31&
    
    Dim objShell, objFolder, objFolderItem, objEnable, objDisable
    Dim folder_Object, target_NIC
    Dim NIC, clsVerb
    Dim str_NIC_Name, strEnable, strDisable
    Dim bEnabled, bDisabled
    
    ' ========================================================
    ' ===== place the name of your network adapter here ======
    ' examples:
    ' str_NIC_Name = "Local Area Connection 2"
    ' str_NIC_Name = "Wireless Connection 1"
    ' ========================================================
    str_NIC_Name = "Ethernet"
    ' ========================================================
    
    strEnable = "En&able"
    strDisable = "Disa&ble"
    
    ' create objects and get items
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
    Set objFolderItem = objFolder.Self
    Set folder_Object = objFolderItem.GetFolder
    
    ' see if the namespace exists
    If folder_Object Is Nothing Then
        Wscript.Echo "Could not find Network Connections"
        WScript.Quit
    End If
    
    Set target_NIC = Nothing
    
    ' look at each NIC and match to the chosen name
    For Each NIC In folder_Object.Items
        If LCase(NIC.Name) = LCase(str_NIC_Name) Then
            ' proper NIC is found, get it
            Set target_NIC = NIC
        End If
    Next
    
    If target_NIC Is Nothing Then
        WScript.Echo "Unable to locate proper NIC"
        WScript.Quit
    End If
    
    bEnabled = True
    Set objEnable = Nothing
    Set objDisable = Nothing
    
    For Each clsVerb In target_NIC.Verbs
        '~ Wscript.Echo clsVerb
        If clsVerb.Name = strEnable Then
            Set objEnable = clsVerb
            bEnabled = False
        End If
        If clsVerb.Name = strDisable Then
            Set objDisable = clsVerb
        End If
    Next
    
    If bEnabled Then
        objDisable.DoIt
    Else
        objEnable.DoIt
    End If
    
    '~ Give the connection time to stop/start
    WScript.Sleep 1000
    WScript.Quit
    
    This is saved as
    and placed in Windows.



    Then I use this little REG edit to add it to the Context menu

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Toggle NIC]
    "icon"="MyIcons.dll,26"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Toggle NIC\command]
    @="WScript C:\\Windows\\ToggleNIC.vbs"
    
    
    Of course you would have to change the icon location if you wanted to use one.

    Works a treat for me.

    This is for a cable connected to an ethernet port though.
     
  4. enigmaelectronica

    enigmaelectronica MDL Novice

    Jul 11, 2011
    29
    9
    0
    Not working for me :(

    Download Folder:
    Captura_error.PNG


    Windows Dir:
    Captura_error_2.PNG

    Windows 10 64 bits Compilation 1706
     
  5. wtarkan

    wtarkan MDL Member

    Sep 1, 2009
    194
    379
    10
    #5 wtarkan, Feb 15, 2018
    Last edited: Feb 15, 2018
    [​IMG]

    – NetDisabler does not install any service
    – NetDisabler Offer 3 Internet blocking methods
    – NetDisabler has a password protection feature
    – NetDisabler is Portable and freeware Application

    Net Disabler supports Cmd parameters . NetDisabler.exe /?” (no quotes) will list all available parameters. See also the screenshot below.

    [​IMG]

    https://www.sordum.org/9660/net-disabler-v1-0/
     
  6. LiteOS

    LiteOS Windowizer

    Mar 7, 2014
    2,198
    974
    90
    powershell

    Code:
    Get-NetAdapter | Disable-NetAdapter
    Get-NetAdapter |Enable-NetAdapter
     
  7. Roscon

    Roscon MDL Novice

    Jul 15, 2017
    20
    15
    0

    You need to know the names of the active network adapters. Use any of these command lines from Powershell:

    Code:
    (Get-NetAdapter | Where-Object {$_.Status -EQ “Up”} | Format-List)
    or
    (Get-NetAdapter | Where-Object {$_.AdminStatus -EQ “Up”}).Name
    or
    (Get-NetAdapter | Where-Object {$_.Status -EQ “Up”}).Name
    
    Alternatively, you can use this command::
    Code:
    ([System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces())
    or
    ([System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()) | Select-Object Name,OperationalStatus
    
    [​IMG]