-3

I'm trying to get my motherboard's serial number through the following command in windows 10 cmd:

wmic baseboard get serialnumber

but I receive this Error:

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

while, this command works on other systems of mine (for example my office pc). What may be wrong with it?

Mohammadreza
  • 79
  • 2
  • 9
  • Thank you. In my case the current directory is different to the directory containing the file to execute. So first of all I have to change the directory by this command: C:\Windows\SysWOW64\wbem and then run wmic command in cmd. – Mohammadreza Aug 01 '19 at 11:35
  • 1
    Note: `wmic baseboard get serialnumber` gets the serial number of your systemboard, while `wmic bios get serialnumber` gets the serial number of your system. They are not the same, so chose carefully which one to use. – Stephan Aug 01 '19 at 11:35
  • Actually I'm using this cmd command in a script as a username. So I'm better to keep it here to help others who may have the same problem in their scripts. I recommend to use cd command in the script before using wmic, as wmic directory may not be the default directory. – Mohammadreza Aug 01 '19 at 11:42
  • in case you guys wonder why you get this error in windows 10 / 11, its because microsoft have removed wmic in their latest windows update. reference: https://winaero.com/microsoft-removed-the-wmic-tool-from-windows-11-dev-builds/ – Ezra Lazuardy Nov 05 '21 at 16:17

1 Answers1

2

In my case the current directory is different to the directory containing the file to execute. So first of all I have to change the directory by this command: cd C:\Windows\SysWOW64\wbem and then run wmic command in cmd.

Mohammadreza
  • 79
  • 2
  • 9
  • 1
    `wmic.exe` should be within your `%path%`. If it's not, your `%path%` variable is messed up, and you will have more problems. – Stephan Aug 01 '19 at 12:21
  • Could you help me how to change cmd current directory through python script? – Mohammadreza Aug 01 '19 at 12:27
  • Fix your `PATH` variable in the system environment-variable editor. It should start with `%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\wbem`. Also, in a script you shouldn't rely on the working directory being implicitly in `PATH`. Windows [can be configured](https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-needcurrentdirectoryforexepathw) to prevent implicit inclusion of "." in the search path that's used by CMD and `CreateProcess`. – Eryk Sun Aug 01 '19 at 13:28