Batch file Script to reboot when no Internet Connection detected?


  1. Posts : 15
    WINDOWS 10
       #1

    Batch file Script to reboot when no Internet Connection detected?


    from time to time my Windows 10 Laptop is unable to connect to the wireless network.

    Tried literally every other "fix"! The only solution is to reboot the LapTop when this happens...

    The best idea I've come up with is to schedule a task to run a script when the computer starts to check if there is a connection to the internet, (maybe pinging my ISP or Google.com) and if that fails then to reboot the computer.

    I've done all kinds of google searches, and searched this forum, but I can't find any example script of this... any detailed help would be appreciated.

    Thanks
      My Computer

  2. lx07's Avatar
    Posts : 5,477
    1903
       #2

    There are scripts for exactly that here batch file - Automatically reboot Windows8 if no internet activity - Super User

    Do think about it though - if you schedule a reboot on loss of internet connection you may lose work if you were doing something that didn't require it (writing a document for example).
      My Computer


  3. Posts : 15
    WINDOWS 10
    Thread Starter
       #3

    lx07 said:
    There are scripts for exactly that here batch file - Automatically reboot Windows8 if no internet activity - Super User

    Do think about it though - if you schedule a reboot on loss of internet connection you may lose work if you were doing something that didn't require it (writing a document for example).
    you make a good point! so what would be a command line for the batch file to cancel the restart should I chose to do so?

    like if I have to connect to a new network, and it takes a few seconds to enter the password
      My Computer

  4. Ztruker's Avatar
    Posts : 10,229
    Windows 10 Pro X64 1909 18363.815
       #4

    Add a timer and a visual prompt, something like this:

    shutdown /r /t 30 /c "Restarting in 30 seconds. Enter shutdown /a from a Run box to cancel."

    That will give you 30 seconds to cancel the restart. You can change 30 to any number you are comfortabel with, depends on how long it take you to open a Run box and type shutdown /a.
      My Computers

  5. ricardobohner's Avatar
    Posts : 230
    Windows 10
       #5

    Dude that can't be the way. Restarting your computer everytime the internet fails. Rather have your Wi-Fi Adapter fixed or buy a USB Wi-fi adapter or check if you have the right drivers. Maybe consider connecting you laptop to the lan, cable may be more stable, maybe something is interfering with the conection like a wireless phone or sound boxes to close to the router or something.
      My Computer


  6. Posts : 15
    WINDOWS 10
    Thread Starter
       #6

    Ztruker said:
    Add a timer and a visual prompt, something like this:

    shutdown /r /t 30 /c "Restarting in 30 seconds. Enter shutdown /a from a Run box to cancel."

    That will give you 30 seconds to cancel the restart. You can change 30 to any number you are comfortabel with, depends on how long it take you to open a Run box and type shutdown /a.
    so I got a workaround but it wont work, heres the script:

    @Echo off

    ping 192.168.1.1
    IF ERRORLEVEL 1 START "" "C:\fixer.exe"

    TIMEOUT /T 10

    ping 192.168.1.1
    IF ERRORLEVEL 1 SHUTDOWN -R -T 00


    that exe can reconnect me to the internet but it wont start when the ping fails, like id want it to, any ideas?
      My Computer


  7. ricardobohner's Avatar
    Posts : 230
    Windows 10
       #7

    I don't think that ping will ever fail cause you are not pinging the internet but a local IP address. 192.168.1.1 is a local IP address for lan. Also you would like to implement something to make this repeat itself otherway it will only run once...

    @Echo off
    :restart
    ping google.com
    IF "%ERRORLEVEL%"==" 1" START "" "C:\fixer.exe"

    TIMEOUT /T 10

    ping 192.168.1.1
    IF "%ERRORLEVEL%"==" 1" SHUTDOWN -R -T 00

    goto restrat


    P.S. If 192.168.1.1 is your router and the connetion to the router is broken than the ping will actually fail.
      My Computer


  8. Posts : 15
    WINDOWS 10
    Thread Starter
       #8

    ricardobohner said:
    I don't think that ping will ever fail cause you are not pinging the internet but a local IP address. 192.168.1.1 is a local IP address for lan. Also you would like to implement something to make this repeat itself otherway it will only run once...

    @Echo off
    :restart
    ping google.com
    IF "%ERRORLEVEL%"==" 1" START "" "C:\fixer.exe"

    TIMEOUT /T 10

    ping 192.168.1.1
    IF "%ERRORLEVEL%"==" 1" SHUTDOWN -R -T 00

    goto restrat


    P.S. If 192.168.1.1 is your router and the connetion to the router is broken than the ping will actually fail.
    you make a good point but the script you made still did not start the exe upon failed ping
      My Computer

  9. ricardobohner's Avatar
    Posts : 230
    Windows 10
       #9

    Try now:

    Code:
    @Echo off
    :restart
    ping google.com
    IF "%ERRORLEVEL%"=="1" START "" "C:\fixer.exe"
    
    
    TIMEOUT /T 10
    
    
    ping google.com
    IF "%ERRORLEVEL%"=="1" SHUTDOWN -R -T 00
    
    
    goto restart
    There was a space before the 1 that's why it failed in " 1"...Also I wrote restart wrong...LOL
      My Computer


  10. Posts : 15
    WINDOWS 10
    Thread Starter
       #10

    ricardobohner said:
    Try now:

    Code:
    @Echo off
    :restart
    ping google.com
    IF "%ERRORLEVEL%"=="1" START "" "C:\fixer.exe"
    
    
    TIMEOUT /T 10
    
    
    ping google.com
    IF "%ERRORLEVEL%"=="1" SHUTDOWN -R -T 00
    
    
    goto restart
    There was a space before the 1 that's why it failed in " 1"...Also I wrote restart wrong...LOL
    that worked! thank you so much!

    - - - Updated - - -

    ricardobohner said:
    Try now:

    Code:
    @Echo off
    :restart
    ping google.com
    IF "%ERRORLEVEL%"=="1" START "" "C:\fixer.exe"
    
    
    TIMEOUT /T 10
    
    
    ping google.com
    IF "%ERRORLEVEL%"=="1" SHUTDOWN -R -T 00
    
    
    goto restart
    There was a space before the 1 that's why it failed in " 1"...Also I wrote restart wrong...LOL
    probably getting a little greedy here, you been such a great help,

    what would be a command line to add "if ping successful exit/close the bat file" ?
      My Computer


 

Related Threads
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 17:09.
Find Us




Windows 10 Forums