Batch File Question

Discussion in 'Scripting' started by HORIZONTAL THINKER, Feb 18, 2013.

  1. HORIZONTAL THINKER

    HORIZONTAL THINKER MDL Member

    Jun 13, 2012
    155
    22
    10
    Hello,

    I was reading on another forum a request for a batch file which would Disable Network Adapters (Local Area Connection and i'd presume Wireless Network Connection).

    And a second batch file which would reverse the above. I've seen many examples of how this is achieved from command line but not via 2 x batch files.

    Has anyone a solution to this?
     
  2. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    84
    10
    #2 Dos_Probie, Feb 18, 2013
    Last edited by a moderator: Apr 20, 2017
    You would use the devcon command in a batch file with the enable or disable command or you could also do it via a .vbs file (see On and Off batch files below for my Wi-Fi) just substitute your hardware id for the one that I used that is specific to my machine.
    Device Manager > Expand Network adapters > right-click WiFi or Lan > Properties > Details > Hardware ids >
    right click your id value and paste into batch
    Code:
    @echo off
    ::Enable Wireless
    devcon enable *DEV_001C
    
    Code:
    @echo off
    ::Disable Wireless
    devcon disable *DEV_001C
     
  3. HORIZONTAL THINKER

    HORIZONTAL THINKER MDL Member

    Jun 13, 2012
    155
    22
    10
    Thanks for your reply Dos Probie. That script would be specific to your machine. But it's a script that will run on any machine running the Windows XP, Vista, & or 8 that he/she is looking for.

    Any suggestions?
     
  4. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    84
    10
    #4 Dos_Probie, Feb 18, 2013
    Last edited by a moderator: Apr 20, 2017
    Try this AIO batch I tested on Win7 and Win8 works on both LAN and WIFI , did not test on XP but since XP supports ipconfig it should work..
    Code:
    @echo off&color a&mode con: cols=70 lines=7
    title [ Toggle Internet Connection - On or Off ]
    :: DosProbie - 02.18.12
    :: DISABLE CONNECTION
    :: Disable if Ping successful..
    ping -n 1 yahoo.com 
    if %errorlevel% EQU 1 goto enable 
    ipconfig /release>nul 2>&1 && ipconfig /release local*>nul 2>&1
    cls
    echo * CONNECTION DISABLED *
    ping -n 4 127.0.0.1>nul
    exit
    :enable 
    :: RESTART CONNECTION
    ipconfig/flushdns>nul 2>&1 && ipconfig /renew>nul 2>&1
    cls
    echo * CONNECTION ENABLED *
    ping -n 4 127.0.0.1>nul
    :end 
    exit