20

I need to run this script I made. This batch should copy compiled program on STM32 Nucleo. It uses wmic to find Nucleo's virtual drive's letter by it's label:

@echo off
for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "NODE_F446RE"') do set nucleo_drive=%%D
IF EXIST %D%\DETAILS.TXT (
  IF EXIST main.bin (
    @echo on
    xcopy main.bin %D%
    @echo off
    echo Copied main.bin on nucleo
  ) ELSE (
    echo Binary not found. Run `mingw32-make` in this directory to compile the project.
  )
) ELSE (
  echo Nucleo drive not found. If needed, edit the `find "NODE_F446RE"` part of this script to refference your nucleo volume name.
)

But I get this error:

'wmic' is not recognized as an internal or external command, operable program or batch file.

I ensured that Windows Management Instrumenation service is running. What else could be wrong?

Tomáš Zato
  • 4,790

6 Answers6

28

WMIC is deprecated and missing by default in Windows 11. Prefer PowerShell's Get-WmiObject cmdlet or, if you don't need to go through WMI specifically, the specific management cmdlets (e.g. Get-LocalUser).

At the time of writing (23H2), WMIC is still available as an optional feature. In the Settings app, go to System → Optional features and click "View features" in the "Add an optional feature" row. Check the box for WMIC and proceed through the installation.

If the feature is already installed or you're on an older OS version, this error indicates that the wmic utility's directory is not found on your PATH. Open the advanced System Properties window (you can open the System page with Windows+Pause/Break) and on the Advanced tab, click Environment Variables. In the section for system variables, find PATH (or any capitalization thereof). Add this entry to it:

%SystemRoot%\System32\Wbem

Note that entries are delimited by semicolons.

Ben N
  • 42,308
8

As @DavidWheatley says wmic is now removed, not just from the latest insider builds but from the latest releases.

Using WMI PowerShell commands, the information @TomášZato needs is available from:

Get-WmiObject -Class Win32_Volume | fl DriveLetter, Label

And here's how to get the BIOS serial number, which is what I was looking for when I found this answer:

Get-WmiObject -Class Win32_Bios | Select SerialNumber

To save typing, -Class can be omitted in both the above; and neither the commands nor the data members are case sensitive, so you can type it all in lower case, e.g. get-wmiobject win32_bios | select serialnumber.

2

If you're using Windows 11, Microsoft has removed WMIC from the latest Insider builds.

Instead, you should now use Powershell commands.

To list all WMI Powershell commands, you can run Get-Command -Noun WMI*.

1

In my case, I had %SystemRoot%\System32\Wbem on the path already, but a recent USB device driver I installed additionally added C:\Windows\System32 to the end of my path, and this stopped Windows from finding the wmic command. When I removed the trailing C:\Windows\System32 from the path, wmic was found again.

AndrWeisR
  • 111
1

Ben helped me w/ his answer below

At the time of writing (23H2), WMIC is still available as an optional feature. In the Settings app, go to System → Optional features and click "View features" in the "Add an optional feature" row. Check the box for WMIC and proceed through the installation.

https://superuser.com/a/1178758/664304

0

When I was using C:\Windows\System32 in the path, I was getting the same warning while installing Tails operating system on an USB stick.

When I change this to: %SystemRoot%\System32\Wbem, everything gets sorted and the warning is gone.

zx485
  • 2,337