How to Connect to Wi-Fi Using CMD: A Complete Guide

Using the command line to manage wireless connections is a powerful tool often overlooked by casual users. Many are accustomed to relying on the Windows graphical interface, believing it's the only way to set up the internet. However, in situations where the graphical interface freezes or automation is required, knowing how to connect to WiFi via the command line becomes a critical skill.

The Command Prompt provides access to certain system functions of the operating system, allowing you to manage network adapters with high precision. Netsh wlan is a utility built into Windows that gives you complete control over wireless networks. It lets you not only connect to access points, but also scan the airwaves, save profiles, and even create hotspots for internet sharing.

This article will cover all the steps involved in using the Wi-Fi console in detail. We'll cover the necessary commands, troubleshooting common errors, and connection optimization techniques. Knowing this will give you more confidence when working with network settings in your environment. Windows 10 And Windows 11.

Launch Command Prompt with Administrator Privileges

The first and most important step is to properly launch the terminal. Standard user mode does not provide sufficient privileges to change network configurations. You need to obtain elevated privileges to allow the system to modify network adapter settings.

There are several ways to open the tool you need. The fastest is to use the search in the Start menu. Type cmd or command line, then select "Run as administrator" from the list of results that appears. This step is critical for executing subsequent commands.

  • 🖱️ Right-click the "Start" button and select "Windows PowerShell (Admin)" or "Terminal (Admin)".
  • 🔍 Press the key combination Win + X and select the appropriate item in the power user menu.
  • 📂 Open File Explorer and follow the path C:\Windows\System32, find the file cmd.exe and run it as administrator.

⚠️ Warning: If you do not run the console as an administrator, you will receive the error "Elevation required" or "Access denied" when you try to run the connection command.

After the black window opens, make sure the window title says "Administrator: Command Prompt." Only then can you begin interacting directly with your computer's wireless module.

Checking the status of the wireless adapter

Before attempting a connection, you must ensure your Wi-Fi adapter is active and functioning properly. The system must see the wireless device, and the drivers must be installed. To begin diagnostics, use the basic status command.

Enter the command in the line netsh wlan show interfaces and press Enter. This command will display detailed information about the current state of the wireless interface. In the list of parameters, find the line "State." If it says "Connected," then the internet is already working and you don't need to reconnect.

If the status shows "Disconnected" or you see a message about no wireless interfaces, the problem may be deeper. Perhaps the driver Wi-Fi adapter It's not installed, or the device is disabled in Task Manager. It's also worth checking whether Airplane Mode is enabled via the laptop's physical buttons or a keyboard shortcut.

What should I do if the adapter is not displayed?

If the show interfaces command returns an error or an empty list, check Device Manager (devmgmt.msc). Find the "Network adapters" section. If the device is marked with a yellow exclamation point, you need to update the driver. If the device is missing, check the physical connection or BIOS/UEFI settings.

Once you've verified that the adapter is visible to the system and active, you can begin scanning for available networks within range. This is the next logical step before entering your credentials.

Scanning for available Wi-Fi networks

To connect, you need to know the exact network name (SSID). In the graphical interface, we simply see a list, but in the console, we need to initiate a scan. The command netsh wlan show networks forces the wireless adapter to scan the air and list all access points found.

The command will return a list with each network numbered. You'll see columns for the network number, SSID (network name), network type (infrastructure), and authentication type. We're specifically interested in the SSID column, as the name must be specified exactly, including case-insensitively.

  • 📡 Pay attention to the signal: the command output usually indicates the signal strength percentage, which can help you choose the best access point if there are several with the same name.
  • 🔒 Security Type: Ensure the network uses the protocol WPA2-Personal or WPA3, as these are safety standards.
  • 📝 Copy the network name: if there are spaces in the name, you will need to include them or enclose the name in quotation marks when entering commands.

Remember or write down the exact network name (SSID). If the name contains special characters or spaces, you must enclose it in double quotation marks in subsequent commands, otherwise the system will interpret the command incorrectly.

Creating a profile and connecting to the network

Now let's move on to the main question: how to connect to WiFi using cmd. The process consists of two steps: creating an XML profile with network information and a password, and then activating that profile. A direct connection without creating a profile is possible, but less reliable for persistent connections.

First, let's create a temporary XML profile file. You can use the add profile command for this, but it's easier to generate one from the command line if you already have a template, or use a simplified direct connection method. We'll look at the most efficient method—creating a profile using a text editor or a single, complex command. However, there's a simpler way for a one-time connection without creating files.

Use the connection command directly. The syntax is as follows:

netsh wlan connect name="Network_Name" ssid="Network_Name"

If the network hasn't been saved previously, the system will ask you to enter a security key. In modern versions of Windows 10 and 11, it's easier to add a profile first. Create a text file with the extension .xml (For example, wifi.xml) with the following content, replacing the data with your own:

<?xml version="1.0"?>

<WLANProfile xmlns="http://www.microsoft.com/network/wlan">

<name>MyWiFi</name>

<SSIDConfig>

<SSID>

<name>MyWiFi</name>

</SSID>

</SSIDConfig>

<connectionType>ESS</connectionType>

<connectionMode>manual</connectionMode>

<MSM>

<security>

<authEncryption>

<authentication>WPA2PSK</authentication>

<encryption>AES</encryption>

<useOneX>false</useOneX>

</authEncryption>

<sharedKey>

<keyType>passPhrase</keyType>

<protected>false</protected>

<keyMaterial>YOUR_PASSWORD</keyMaterial>

</sharedKey>

</security>

</MSM>

</WLANProfile>

Then add this profile with the command netsh wlan add profile filename="path\to\file\wifi.xml"After adding, connect with the command netsh wlan connect name="MyWiFi"This ensures that all encryption parameters are met.

☑️ Checklist before connecting

Completed: 0 / 4

Managing saved Wi-Fi profiles

The operating system stores a history of all the networks you've ever connected to. This is convenient for automatic connections, but sometimes it creates conflicts or requires deleting old data. These profiles are also managed through netsh.

To see a list of all saved profiles, enter the command netsh wlan show profilesYou'll see a list of all network names. If you want to find out the password for an already connected network, use the command netsh wlan show profile name="Network_Name" key=clearIn the "Security Settings" section, the "Key Content" field will display the password in clear text.

Team Description of action Example of use
show profiles Displays a list of all saved networks. netsh wlan show profiles
delete profile Deletes a specific network profile netsh wlan delete profile name="Cafe"
export profile Saves the profile to an XML file. netsh wlan export profile name="Home" folder="C:\"
add profile Imports a profile from an XML file. netsh wlan add profile filename="C:\wifi.xml"

Deleting profiles is useful if you've changed your router password, but your computer is still trying to connect with the old password. Clearing the list can also speed up the network search process when switching between locations.

📊 How often do you use the command line?
Every day for work
Only when the GUI is glitchy
Rarely, I prefer GUI
I don't use it at all

Diagnosing and troubleshooting connection problems

Even if you enter commands correctly, errors may occur. Driver failuresIP address conflicts, or Wi-Fi service issues are common causes of connection failure. If the connection command returns an error, first check your Wi-Fi service.

Enter services.msc In the command line (or via Run), find the WLAN AutoConfig service. Make sure it's running and the startup type is set to Automatic. Without this service running, any commands won't work. netsh wlan will not work.

⚠️ Note: Command line interfaces and available options may vary slightly depending on your Windows version and system updates. If the command doesn't work, check the syntax in the official Microsoft documentation for your OS version.

Also try resetting your network settings. Command netsh int ip reset And netsh winsock reset Helps restore basic network protocols. After completing these steps, a computer restart is required. This often resolves issues where the adapter "sees" the network but cannot obtain an IP address.

Frequently Asked Questions (FAQ)

Is it possible to connect to a hidden network via cmd?

Yes, this is possible. When creating an XML profile (as described in the section on creating a profile), you need to add the tag <hidden>true</hidden> inside the section <SSIDConfig>After adding such a profile with the command add profile, the system will try to connect to the hidden network even if it is not broadcasting the SSID.

What to do if netsh command is not found?

Team netsh is a system command and is present in all versions of Windows. If the system reports "not an internal or external command," check if the PATH environment variable has been modified, or try specifying the full path: C:\Windows\System32\netsh.exe.

How do I find out the password for the Wi-Fi I'm connected to but don't remember?

Use the command netsh wlan show profile name="Your_Network_Name" key=clearIn the output, find the "Security settings" section and the "Key Content" line. This will contain the password in clear text.

Why is connecting via cmd better than via interface?

The CMD interface provides access to real-time logs, allows connection scripting (automation), and allows working in environments where the Explorer.exe graphical shell may be unavailable or frozen. It's a tool for more in-depth diagnostics.

Is it possible to share Wi-Fi via the command line?

Yes, using the command netsh wlan set hostednetwork You can turn your laptop into a hotspot. However, in Windows 10/11, this feature is often replaced by the standard "Mobile Hotspot" mode in Settings, but the CMD method still works at the driver level.