Wmic or Windows Management Instrumentation command-line tool is an operation that you can take help to search for much hardware-related information, such as the serial number of hardware components, RAM size, attached drive units, etc. It usually works flawlessly and you can use it with a variety of scripting languages. But what if you receive “WMIC is not recognized as an internal or external command, operable program or batch file” on the shell? Usually, this occurs when the WMI service is stopped or not yet started on the system. You can find a quick resolution for this issue from here.
Fix 1 – Use the correct location
If you are reading this error message on a terminal, it should be an incorrect location issue.
1. The correct location of the WMIC.exe is this –
C:\Windows\System32\wbem\WMIC.exe
2. So, the correct code syntax in php should be like this –
echo shell_exec(address of WMIC.exe query)
Example – Suppose you are trying to get the CPU temperature reading through PHP. So, the code will be –
echo shell_exec("C:\\Windows\\System32\\wbem\\WMIC.exe cpu get loadpercentage");
This will definitely work and solve your issue.
Fix 2 – Automate the Windows Management Instrumentation service
Windows Management Instrumentation is an essential service that is needed to be started automatically.
1. You have to open the Services. To open it, press the Windows key+R keys together.
2. Then, type “services.msc” and click on “OK“.
3. When the Services page appears, find the “Windows Instrumentation Service” simply scrolling down through the list of services.
4. Once you have found it, double-tap it.
5. You have to set this service to run automatically at the system startup. Set the ‘Startup type:’ to “Automatic” mode.
6. If the services aren’t running, tap “Start” to start the service now.
7. After that, tap “Apply” and “OK“. This will save these changes.
Close the Services window. Now, try running the WMIC code again.
Fix 3 – Add a new variable
Add a new WMIC environment variable to your system.
Step 1 – Verify the location of wbem
Though the default location of wbem is –
C:\Windows\SysWOW64\wbem
Still, you should verify the location of the instrument once more. So, follow these steps.
1. Open the File Explorer.
2. Then, head this way –
C:\Windows\SysWOW64\wbem
3. Inside the wbem folder, look for the “WMIC” app.
4. Once you have found it, select the address. Now, just right-tap it and click “Copy” to copy the address.
You have to close the File Explorer.
Step 2 – Add a new variable
Now, you can add a new environment variable.
1. To open the File Explorer, you have to press the ⊞ Win key+R.
2. Then, write down this “sysdm.cpl” and tap on “OK“.
This will open up the System Properties window.
3. When the System Properties panel opens up, go to the “Advanced” tab.
4. Here, tap on the “Environment Variables...”.
5. Now, in the System variables section, click on the “New…” option to create a new variable.
6. After that, set the ‘Variable name:’ to “WMIC Path“.
7. Next, paste the copied location in the ‘Variable value:’ box.
[ It is – “C:\Windows\SysWOW64\wbem“]
8. Once you have done this, tap “OK” to save the changes.
9. Tap “OK” to save this modification.
10. Coming back to the System Properties page, tap “OK” to save the changes.
After defining the variable you should restart your computer once. Then, try to run the WMIC code again. This should work and solve your issue.