[SOLVED] Broken turn off/on Ethernet connection via shortcut. Batch file/app needed

Discussion in 'Windows 8' started by anythingUlike, Dec 4, 2013.

  1. anythingUlike

    anythingUlike MDL Junior Member

    Apr 4, 2011
    79
    9
    0
    #1 anythingUlike, Dec 4, 2013
    Last edited: Dec 4, 2013
  2. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,020
    945
    60
    #2 user_hidden, Dec 4, 2013
    Last edited by a moderator: Apr 20, 2017
    use something like this as a check:

    Code:
    ping -n 1 yahoo.com 
    if %errorlevel% EQU 1 goto enable 
     
  3. anythingUlike

    anythingUlike MDL Junior Member

    Apr 4, 2011
    79
    9
    0
    O man, that was easy one!
    So finally I changed batch to:
    Code:
    @echo off
    cls
    
    :Check
    ping -n 1 192.168.1.254 
    if %errorlevel% EQU 1 goto Enable_LAN
    if %errorlevel% EQU 0 goto Disable_LAN
    
    :Enable_LAN
    netsh interface set interface "Ethernet" Enable
    goto :EOF
    
    :Disable_LAN
    netsh interface set interface "Ethernet" Disable
    goto :EOF
    
    :EOF
    placed in some location, made shortcut for this batch and set up run shortcut with admin rights.
    It's working flawlessly.

    Thank you user_hidden and a beer for you:drunk:
     
  4. BigW

    BigW MDL Member

    Apr 25, 2010
    198
    53
    10
    May I ask why you have the need to regularly turn off/on your Ethernet connection? I've the need for it only a few times a year or when I've to install new networking equipment which isn't realy that often. Even if you have to do this once or twice a month you don't have much hassle doing it in the UI.
     
  5. Preza

    Preza MDL Novice

    Mar 19, 2014
    1
    0
    0
    Hey guys
    I'm having the same problem with Ethernet shortcut.
    I don't know anything about programming so I couldn't solve my problem with the solutions above.
    can anyone help me, please?
     
  6. Ming_the_Merciless

    Ming_the_Merciless MDL Member

    Feb 7, 2014
    139
    48
    10
    You don't have to program anything. buuuuuuu190 has provided the code for you in post 3 of this thread. All you need to do is:

    1 - open (run) notepad
    2 - copy code posted by buuuuuuu190 in post 3
    3 - paste into notepad
    4 - save file as a .bat (saving as ".bat.txt" won't work! - you can't use the notepad defaults - change "File type" from the default ".txt" to "any" to do this)

    You're done! You must run the file with elevated privileges (right-click and select "Run as administrator")