cordova-cli: Error: Command failed: wmic os get Caption 'wmic' is not recognized as an internal or external command, operable program or batch file.

Bug Report

What does actually happen?

Im getting this error after I updated to cordova 9.0.0

C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index
.js:347
                throw err;
                ^

Error: Command failed: wmic os get Caption
'wmic' is not recognized as an internal or external command,
operable program or batch file.


    at makeError (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_m
odules\execa\index.js:174:9)
    at Function.module.exports.sync (C:\Users\admin\AppData\Roaming\npm\node_mod
ules\cordova\node_modules\execa\index.js:338:15)
    at windowsRelease (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\n
ode_modules\windows-release\index.js:34:24)
    at osName (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node_modu
les\os-name\index.js:39:18)
    at new Insight (C:\Users\admin\AppData\Roaming\npm\node_modules\cordova\node
_modules\insight\lib\index.js:37:13)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\cordo
va\src\telemetry.js:26:15)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

Information

Command or Code

cordova -v cordova help cordova build android

Version information

Cordova 9.0.0 Window 7 64x

Checklist

  • [x ] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 31 (5 by maintainers)

Most upvoted comments

thanks @janpio, adding “c:\Windows\System32\wbem” to my path environnement variable solved this problem

Related: https://github.com/sindresorhus/windows-release/issues/10

Do you have c:\Windows\System32\wbem\WMIC.exe? Then this might help: https://superuser.com/a/1434268/25933

Anything strange about your Windows installation?

Uhmmm its not original copy

I’ve made a pull request with a fix that uses powershell where wmic fails. Hoping it gets accepted. If not I cloned the repo and made a new version using the fix. Don’t know if it’s of any help to anyone, but here’s the node package:

https://www.npmjs.com/package/windows-release-ps

adding “c:\Windows\System32\wbem” to my path environnement variable solved this problem with Node v10 Also restart your cmd

Any fresh Cordova installation should have the version of windows-release that has the fix, due to compatible semver ranges. No need to change your PATH.

If you still encounter this problem, re-install Cordova and check that the version of windows-release used by it is at least 3.3.0.

For all of you out there, if this problem still persists: Add the following directory to the ‘Path’ variables in System Variable (or User variable, depends on you) C:\Windows\System32\wbem

c:\Windows\System32\wbem is suppose to be added to the Path variable, not a cordova variable. Path contains several paths, separated by a semicolon.

Prepend it with c:\Windows\System32\wbem;<your existing path here>

After you change environment variables, you must restart your terminal.

Just like @ArthurHNL says, adding wbem to the system path won’t work in future Windows releases since WMIC is deprecated. That’s why the windows-release package was updated to use Powershell I stead of WMIC as the first choice.

For me, this issue started occurring when I enabled Windows Credential Guard on my device. It should also be noted that the entire wmic utility is deprecated:

image

My opinion here is that Cordova is relying on a deprecated Windows component that may show undefined behaviour now and in the future since Microsoft will not keep testing whether new Windows versions and / or features might break it.

I found that this command can replace the call to wmic alltogether:

powershell (Get-CimInstance -Class Win32_OperatingSystem).Caption

I’ll file an issue for this at the repository for the WindowsRelease module.