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

5

2

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 - Reinstate Monica

Posted 2017-02-14T13:16:49.400

Reputation: 2 932

1Try absolute path to wmic, it should live in C:\Windows\System32\wbem – Alex – 2017-02-14T13:20:45.560

Answers

17

This 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

Posted 2017-02-14T13:16:49.400

Reputation: 32 973

3+1 for a shortcut I didn't know about :) – DavidPostill – 2017-02-15T00:02:51.793

Before going through these steps, it's probably worth navigating to this folder in an elevated (run as admin) command-line window to ensure the command is really there. – FreeText – 2018-10-01T21:09:38.933

0

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

Posted 2017-02-14T13:16:49.400

Reputation: 101