Turn on Wi-Fi via command line

5,386

As far as I know and could find after searching extensively, there is no way to do this directly. Turning off Wi-Fi is something similar to airplane mode, and there is no way to turn off airplane mode with commands either. An extremely ugly hack would be to write a script that simulates keystrokes to do the task. In vbscript, this would look like (tested, you may need to change the timeouts)

set shell = CreateObject("WScript.Shell")
shell.run"ms-settings:network-wifi"
WScript.Sleep 2500
shell.SendKeys" "
WScript.Sleep 1500
shell.SendKeys"%{F4}"

Then you can call the script as

cscript toggle-wifi.vbs

You could also work with ms-availablenetworks: which takes less time to open

Share:
5,386

Related videos on Youtube

Chad
Author by

Chad

I am a software engineer.

Updated on September 18, 2022

Comments

  • Chad
    Chad over 1 year

    I have a batch file/script that disconnects from the current WiFi network, connects to a specific WiFi network then sets a static IP address, and it works on Windows 7 but not on Windows 10 if the Wi-Fi is "turned off". How do I "turn on" the Wi-Fi via the command line (or batch file/script since I can normally figure out the syntax of one from the other)?

    If it helps, the control panel -> Network and Internet -> Network Connections, Wi-Fi is enabled, but has a red X on it and netsh wlan connect name=%ltName% does not work (where ltName is set to the correct Wi-Fi profile name and it is a known network). Also, the Settings, Wi-Fi slider button at the top of the page says off.

    Also, the script is run as Administrator and running Windows 10 Pro version 1607.

    Script:

    :: disconnect from the current network
    netsh wlan disconnect
    
    set ltName=insertNameHere
    
    :: now connect to the wifi
    netsh wlan connect name=%ltName%
    netsh interface ip set address "Wi-Fi" static xxx.xxx.xxx.xxx 255.255.255.0
    
    ::pause
    
    • Neelix
      Neelix about 6 years
      Can you post your existing script? What version of Windows 10 are you running? I have run into problems where things worked fine with 1607 and no longer function on 1709.
    • Chad
      Chad about 6 years
      Ok, I added the script and version. I am running 1607.
    • Neelix
      Neelix about 6 years
      I see now. Have you tried the enable command: netsh interface set interface "Interface Name" enabled superuser.com/questions/696270/how-to-turn-on-wifi-via-cmd
    • pulsejet
      pulsejet about 6 years
      @Neelix, interestingly, it doesn't seem to work
    • Neelix
      Neelix about 6 years
      I tested this command on Win10 1607 and 1703 and it worked to enable and disable the adapter as long as airplane mode is off. It doesn't sound like you are using airplane mode so this should work. Assuming your adapter name is "wi-fi" Run cmd as Administrator and copy and paste everything between the "": "netsh interface set interface wi-fi enabled"
    • pulsejet
      pulsejet about 6 years
      @Neelix, disabling the adapter and disabling WiFi in windows 10 are not the same thing. Simple test: when you disable the adapter, the WiFi button vanishes entirely from the network window!
    • Chad
      Chad about 6 years
      @Neelix, the netsh interface set interface "Interface Name" enabled command does not appear to fix the issue. I can disable and enable the "Wi-Fi" with the wifi turned on or off. They seem to be independent of each other.
  • Chad
    Chad about 6 years
    That VB script is cool, but the "ms-settings:network-wifi" didn't bring up the wifi page. Is there a different string that will do that? This is the first time I have ever written a visual basic script so I have no clue how those strings work or where/how to figure it out.
  • Chad
    Chad about 6 years
    I tried shell.run"ms-settings:network-wifi" on a different computer and it worked... Not sure why it works on one computer but not another.
  • pulsejet
    pulsejet about 6 years
    @Chad that's interesting ... are both updated to the same version?
  • Chad
    Chad about 6 years
    No. It works on 1703, but doesn't on 1607.