Click here to Skip to main content
14,036,452 members
Click here to Skip to main content
Add your own
alternative version

Stats

2.7K views
2 bookmarked
Posted 4 Oct 2018
Licenced CPOL

Work Around Windows 10 WiFi Reconnection Failing

, 4 Oct 2018
Rate this:
Please Sign up or sign in to vote.
Schedule a task to run this script, which checks whether Windows has [re]connected to the specified router after startup, sleep, or hibernation – and attempt to connect if not.

Introduction

Many Windows users who upgraded their computers to Windows 10 have found they have a problem with Windows intermittently not automatically reconnecting to their WiFi router after startup, sleep, or hibernation. There are a lot of possible solutions offered online for this – from running chkdsk, to ensuring the home network is set to 'Private', to updating network drivers, to disabling power management on the network adaptor in Device Manager, to turning off 'fast start-up' in Power Options – and one or more of these solutions may work for you, so please try them first.

But many people have jumped through all of those hoops to no avail and the only advice I've seen after that is to reinstall Windows from scratch – which seems to me like rebuilding your house because the front door is sticking! So I decided to go down a different route and write a batch script to check whether the home WiFi router is connected and try to connect to it if not. Then I scheduled a task to run the script on startup or resume.

I hope this article will help anyone else facing this problem.

Requirements

A Windows admin account will be needed to run the script and to schedule a task to run regardless of whether any user has logged on or not. If you don't have an admin account, you will need to speak to your network administrator.

Using the Code

Paste this code into a batch file (given the extension .bat) and edit 'HOME-ROUTER' to your own router's SSID.

@ECHO OFF
REM Make up to three attempts to connect to the router
SETLOCAL EnableDelayedExpansion
set LOGFILE=output.txt
call :CHECK >> %LOGFILE%
exit /b

:Check
ECHO ---------------------------------------------
ECHO Start check at %date% %time%
set "myRouter=HOME-ROUTER"
set "host=8.8.8.8"
set counter=1
:WHILE
if !counter! EQU 4 goto :failpoint
ping -n 1 "!host!" | findstr /r /c:"[0-9] *ms"
if !errorlevel! EQU 0 (
  if !counter! EQU 1 (
    REM It's the first pass, so the WiFi is already connected
    ECHO Already connected
  ) else (
    REM It's a subsequent pass, so this script made the connection
    ECHO Connected OK
  )
  goto :exitpoint
) else (
  ECHO Not connected
  ECHO Connection attempt !counter!
  netsh wlan connect !myRouter!
  timeout 5
  set /a counter+=1
  goto :WHILE
)
:failpoint
ECHO Failed three connection attempts
:exitpoint

Save the file somewhere on your computer and test it directly by disconnecting your WiFi and running the batch file to see if it reconnects the WiFi okay. Once you have established that it does, you can go ahead and create a scheduled task to run it at the appropriate times.

Notes

I've used one of Google's DNS IP addresses (8.8.8.8) as a reliable host to check, but you could equally use the IP address or share name of any local device (such as a wireless printer – e.g. 192.168.1.29 or 'HP_LaserJetPro') if you know it will always be available. This may be preferable if your internet connection is unreliable or 'on demand'.

In no way am I an expert with the Windows command line and/or batch file coding. I've simply put this code together – after a lot of head-scratching and hair-pulling – from snippets I've found online. So it may not be the most efficient, robust, or effective way to accomplish this task. I am always open to constructive criticism and advice on how to improve it.

Schedule the Task

  1. Start the Task Scheduler (press the Windows key + R to open the Run box, type taskschd.msc and press Enter).
  2. Click on Create Task… in the 'Actions' pane.
  3. Name the task.
    TipStart your own task names with an underscore so they appear at the top of the list.
  4. Under 'Security options' select Run whether user is logged on or not.
    Note: If you are not currently logged into Windows with an admin account, you will need to change the user to an admin account by clicking the Change User or Group… button.
  5. Check the Run with the highest privileges box.
  6. Go to the 'Triggers' tab and add two New… triggers:
    1. For system startup:
      1. Select At startup from the drop-down list at the top.
      2. Check the box Delay task for: and set it for 30 seconds.
        This helps to ensure Windows has started the services necessary for the network connection to be established.
      3. Click OK.
    2. For resuming from sleep or hibernation:
      1. Select On an event from the drop-down list at the top.
      2. Select System from the 'Log' drop-down.
      3. Select Kernel-Power from the 'Source' drop-down.
      4. Enter 107 in the 'Event ID' box.
      5. Check the box Delay task for: and set it for 30 seconds.
        The delay here may be unnecessary, but it can't do any harm.
      6. Click OK.
  7. Go to the 'Actions' tab and add this New... action:
    1. Select Start a program from the 'Action' drop-down.
    2. Enter the full path and script name in the 'Program/script' box – or use the 'Browse…' button to locate it.
    3. In the Start in (optional): box, enter the path where you want the output.txt log file to be created, even if it's the same path as the batch file. Otherwise, it won't get created at all.
      Alternatively, you could edit the LOGFILE constant in the batch file itself, to give it a full path.
    4. Click OK.
  8. Go to the 'Conditions' tab and uncheck the option Start the task only if the computer is on AC power.
  9. Click OK.
  10. When prompted, enter the password for the selected admin account.

That should be it. Test every restart scenario and ensure the log file 'output.txt' is being updated each time.

History

  • v1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Antagony
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
Praisemy brute force approach Pin
noherr8-Oct-18 23:05
membernoherr8-Oct-18 23:05 
QuestionSee citation Pin
gggustafson8-Oct-18 7:54
professionalgggustafson8-Oct-18 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190424.1 | Last Updated 5 Oct 2018
Article Copyright 2018 by Antagony
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid