serial-number icon indicating copy to clipboard operation
serial-number copied to clipboard

"'wmic' is not recognized as an internal or external command" on Windows

Open chetbox opened this issue 3 years ago • 3 comments

We have an Electron app that uses a serial number from this library to validate license keys via serial number.

One of our customers is getting the following error (which we found via automated crash reporting):

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

Is there a workaround we need for this user? Do they need to the fix the %PATH% on their machine? Or is this a valid environment this library does not take into account?

Thanks for this library by the way, it's been super helpful!

chetbox avatar May 07 '21 14:05 chetbox

They probably have issue with PATH, but looks like you can work around this by passing second parameter (or --cmdprefix if using cli) with path where to look for wmic (make sure it's only added on Windows if it's cross-platform)

var serialNumber = require('serial-number');
 
serialNumber(function (err, value) {
    console.log(value);
}, "%SystemRoot%\\System32\\Wbem\\") // <--

ragauskl avatar Oct 24 '21 19:10 ragauskl

According to Microsoft here,

The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 General Availability Channel release of Windows Server.

It has been replaced by Windows PowerShell for WMI. The following command returns the Serial number.

Get-CimInstance -ClassName Win32_BIOS -Property SerialNumber |
Select-Object -ExpandProperty SerialNumber

The code need to be adjusted to use wmic or PowerShell depending on the windows version pre/post 11.

Any volunteer ?

FabienLydoire avatar Jan 16 '23 09:01 FabienLydoire

I made PR https://github.com/es128/serial-number/pull/18 to fix this issue.

FabienLydoire avatar Jan 27 '23 12:01 FabienLydoire