Batch file Script to reboot when no Internet Connection detected? Solved

  1.    #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 ComputerSystem Spec

  2.    #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 ComputerSystem Spec

  3.    #3

    lx07 said: View Post
    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 ComputerSystem Spec

  4. Ztruker's Avatar
    Posts : 7,819
    Windows 10 Pro X64 1809 17763.437
       #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 ComputersSystem Spec

  5.    #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 ComputerSystem Spec

  6.    #6

    Ztruker said: View Post
    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 ComputerSystem Spec

  7.    #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 ComputerSystem Spec

  8.    #8

    ricardobohner said: View Post
    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 ComputerSystem Spec

  9.    #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 ComputerSystem Spec

  10.    #10

    ricardobohner said: View Post
    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: View Post
    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 ComputerSystem Spec


 

Related Threads
Automatically Run Batch Script in Installation and Upgrade
Hi everyone When the windows installation is finished, automatically run batch script. How can I do that? Thanks ;)
I'm looking for a batch script that can: Pull the single row taskbar to a 3 row taskbar and lock it in place in its default location (bottom). Change the time format at the bottom right corner from default to have e.g. "2:00 AM" in the first...
Firstly thank you for even clicking on this thread as I understand that this probably isn't meant to be here. The scenario is that I'm trying to write a script that incorporates the result of a ping to an IP and then based on the result do...
I've looked all over and was wondering if I could get some help here. I work where there are public machines, and we tell people NOT to use Internet Explorer, BUT only 10% of people actually adhere to this. That's life. I've noticed that with...
Batch script question in General Support
Hello, I want make a batch script to delete a spefic folder on the C disk, but how can I get only that spefic folder? I got this: FOR /D %%p IN ("C:\USERS\%USERNAME%\Downloads\*.*") DO rmdir "%%p" /s /q cd C:\USERS\%USERNAME%\Downloads\ del...
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 16:13.
Find Us