The UtilityWMIC 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 LibraryTo enable and disable the interface you use the Win32_NetworkAdapter class.
The InterfaceTo get the interface name you can list the interfaces:
wmic path Win32_NetworkAdapterBut 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 Dump Interface InformationIf you want to dump all the Information:
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection"If you want to get a single item (e.g. MAC Address):
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection" get MacAddress
To Enable the InterfaceCall the enable method:
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection" call enable
To Disable The InterfaceCall the disable method:
wmic path Win32_NetworkAdapter where NetConnectionID="Wireless Network Connection" call disable
Call ErrorsA successful change of the interface:
Executing (\\IGOR\root\cimv2:Win32_NetworkAdapter.DeviceID="11")->enable()An unsuccessful one will have a non-zero ReturnValue and message.
Method execution successful.
instance of __PARAMETERS
ReturnValue = 0;
Interface Name ErrorsIf you use an invalid name you'll see:
No Instance(s) Available.
CygwinFor unknown reasons, if you use a single pair of quotes in the command, you get the error:
Node - IGORWhere IGOR is the name of the computer. To fix this you need to nest another pair of quotation marks inside the first. For example:
Description = Invalid query
wmic path win32_networkadapter where NetConnectionID="'Wireless networK connection'" get Macaddress
Non-Interactive SSHIf 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'