The Utility
WMIC is the
Windows Management Interface Command-line Utility a command-line interface to the WMI libraries. Here I'm going to focus on enabling and disabling the wireless interface.
Note: Since these are
DOS commands they are case-insensitive (even inside quotes) so the mixed cases are only used to make it easier to read.
The Interface
To get the interface name you can list the interfaces:
wmic path Win32_NetworkAdapter
But this will dump a mess of lines so here we'll assume you just know it's
Wireless Network Connection (if you click on the wireless icon on the TaskBar you'll see that this is the name above the list of visible access points). This value is used for the
NetConnectionID in the command.
To Enable the Interface
Call the
enable method:
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection" call enable
To Disable The Interface
Call the
disable method:
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection" call disable
Errors
Call Errors
A successful change of the interface:
Executing (\\IGOR\root\cimv2:Win32_NetworkAdapter.DeviceID="11")->enable()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 0;
};
An unsuccessful one will have a non-zero ReturnValue and message.
Interface Name Errors
If you use an invalid name you'll see:
No Instance(s) Available.
Maddening Variations
Cygwin
For unknown reasons, if you use a single pair of quotes in the command, you get the error:
Node - IGOR
ERROR:
Description = Invalid query
Where
IGOR is the name of the computer. To fix this you need to nest another pair of quotation marks inside the first. For example:
wmic path win32_networkadapter where NetConnectionID="'Wireless networK connection'" get Macaddress
Non-Interactive SSH
If you pass in the command as a string to an SSH Connection (e.g. in Paramiko), you need to put quotes around the whole thing and escape the nested quotation marks:
'wmic path win32_networkadapter where NetConnectionID="\'Wireless networK connection\'" get Macaddress'