Restart Wi-Fi adapter by Batch Script

If you’re like me, you have a laptop that for no known reason has the wifi turn off abruptly and won’t turn back on unless you reset it (fastest way was to just use the troubleshooter). It is a new laptop, so it shouldn’t be doing anything like this. Whatever.

I wanted to have a faster way to reset it than going into Windows troubleshooter or manually typing commands every time, so I created a batch file (.bat) that runs what the Windows troubleshooter does anyway. But it also looks like no one really posts this simple fix online, or Google’s search algo just steers users away from How-To’s on batch files unless it’s explicitly requested. So, I thought I’d just make it available, so you can create your own batch file. Maybe Google’s algo won’t direct anyone here. We’ll see. So, here’s the simple script:

echo on
netsh interface set interface Wi-Fi disable
netsh winsock reset
netsh interface set interface Wi-Fi enable

Explanation:

  1. Line 1 basically tells the command prompt to display whatever command is called, for the user, so the user knows what is going on when.
  2. Line 2 commands the network shell (netsh) to call upon a resource (interface) manipulate it (set), namely the wifi adapter (interface Wi-Fi) and change its value to OFF (disable). Your interface’s name might vary. Check by running ‘netsh interface show interface’ in a command prompt, and it’ll show you.
  3. Line 3 commands the network shell to call upon Windows Sockets API (winsock) and manipulate it to a zero state (reset)
  4. Line 4 commands the network shell to call upon a resource manipulate it, namely the wifi adapter and change its value to ON (enable)

If you got this far and you don’t know how to run it, see the warning below. But to cut to the chase: paste the code block in Notepad and save as a new file. Select “all file types” (rather than .txt files), and manually add “.bat” to the end of the file. This forces the file to be saved as a Batch File format (.bat), rather than the default for Notepad (.txt). Second, you need to run it in a Command Prompt. Third, this requires admin privileges. You can just save it on your desktop, right-click “Run as Administrator”, and you’re good.

Obligatory warning: if any of this seems totally foreign to you, google each of the things I mentioned. If any of this makes you uncomfortable, or if you have to be sneaky to get admin access, then just don’t do this. Ask someone you trust who is more competent to do it. You’d hate to turn off your wifi, not know how to turn it back on, only to not have internet access to google “how to fix the mess I’m in now”. Don’t cut off the branch you’re sitting on.

Maybe some other time I’ll post my script for resetting a printer spooler. I bet that’s online somewhere already, right?

P.S. I know I could just use Linux. That discussion is for another time. :þ