wmic comand in cmd

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

wmic comand in cmd

#1 Post by imothep85 » 13 Jun 2014 17:16

hi to all, i have a little problem

i try to get the serialnumber from the bios
so id do:

wmic bios get serialnumber


and the problem is, that gives me:

"serialnumber"
xxxxxxxxxxxxxx (xxxx is the serialnumber)

i need to save JUST the serial number witout the text "serialnumber" in a txt file, how to do that???

thanks to all.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: wmic comand in cmd

#2 Post by Squashman » 13 Jun 2014 20:51

Code: Select all

@echo off
for /f "skip=1" %%G in ('wmic bios get serialnumber') do >>serial.txt echo %%G&GOTO BREAK
:BREAK

Or Dave's way.

Code: Select all

@echo off
for /f "skip=1" %%G in ('wmic bios get serialnumber') do for /f "delims=" %%H in ("%%G") do >>serial.txt echo %%H

imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

Re: wmic comand in cmd

#3 Post by imothep85 » 14 Jun 2014 02:39

hi thanks, i try to do a bat with your code but that dont want to run :s that doenst save the file also :s

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: wmic comand in cmd

#4 Post by foxidrive » 14 Jun 2014 03:08

Which code did you try?

imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

Re: wmic comand in cmd

#5 Post by imothep85 » 14 Jun 2014 04:44

i tried the two codes :s im under windows 7

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: wmic comand in cmd

#6 Post by foxidrive » 14 Jun 2014 06:21

They look like they should work - the answers have been edited so try them again.

I can't test it because wmic bios get serialnumber doesn't give me a serial number on my computer.

This should work to get the result in a file too.

Code: Select all

wmic bios get serialnumber | findstr "[0-9]" >serial.txt

imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

Re: wmic comand in cmd

#7 Post by imothep85 » 14 Jun 2014 06:33

well i was looking trought internet , but under windows7 its different :s

sand also i saw some people dont have bios serial number, i dont know why, so i try

wmic diskdrive get serialnumber
but i still get the words "serial number"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: wmic comand in cmd

#8 Post by foxidrive » 14 Jun 2014 06:39

What did the code I provide give you?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: wmic comand in cmd

#9 Post by Squashman » 14 Jun 2014 06:45

My code was Tested on Windows 7.

aGerman
Expert
Posts: 4745
Joined: 22 Jan 2010 18:01
Location: Germany

Re: wmic comand in cmd

#10 Post by aGerman » 14 Jun 2014 07:13

May also have to do with the current working directory if it doesn't write to the file. First try echoing without redirection.
Another approach

Code: Select all

@echo off &setlocal
for /f %%i in ('wmic bios get serialnumber /value') do for /f %%j in ("%%i") do set "%%j"
echo %serialnumber%
pause

imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

Re: wmic comand in cmd

#11 Post by imothep85 » 14 Jun 2014 07:55

well actually i try and i try again, i m on windows 7 64bits, i put your code into a txt file wich i rename to test.bat, i put that on the folder c:\test, i tried to use the bat ouside or on others folders but that change nothing :s


im trying with this

@echo off
setlocal
For /F "tokens=2 delims==" %%A in ('WMIC Path Win32_physicalmedia Get SerialNumber /value') Do (
for %%B in (%%A) Do (Set "HDSerial=%%B")
)
Echo. %HDSerial%


but that doenst work also :s when i do wmic Win32_physicalmedia Get SerialNumber it gives me the serial number but why thoses bat dont work?
Last edited by imothep85 on 14 Jun 2014 08:28, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: wmic comand in cmd

#12 Post by Squashman » 14 Jun 2014 08:09

imothep85 wrote:well actually i try and i try again, i m on windows 7 64bits, i put your code into a txt file wich i rename to test.bat, i put that on the folder c:\test, i tried to use the bat ouside or on others folders but that change nothing :s

Tested on Windows 7 64bit!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: wmic comand in cmd

#13 Post by foxidrive » 14 Jun 2014 08:25

imothep85 wrote:well actually i try and i try again, i m on windows 7 64bits, i put your code into a txt file wich i rename to test.bat, i put that on the folder c:\test, i tried to use the bat ouside or on others folders but that change nothing :s



Put pause as the last line. Do you see an error on the console?

WMIC needs administrator permissions I think, and the default folder will be the system32 folder, which you can't write to.

imothep85
Posts: 11
Joined: 13 Jun 2014 17:12

Re: wmic comand in cmd

#14 Post by imothep85 » 14 Jun 2014 08:44

well actually i can write without problem to my c:\test folder the file "serial.txt"

but inside i allways have the line "serialnumber" wich i want to remove and only keep the number.

also my windows is windows7 ultimate edition 64bits

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: wmic comand in cmd

#15 Post by Squashman » 14 Jun 2014 09:20

Code: Select all

C:\test>ver

Microsoft Windows [Version 6.1.7601]

C:\test>set programfiles
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)

C:\test>type serial.bat
@echo off
echo my way
for /f "skip=1" %%G in ('wmic bios get serialnumber') do >>serial.txt echo %%G&GOTO BREAK
:BREAK

echo Dave's way
@echo off
for /f "skip=1" %%G in ('wmic bios get serialnumber') do for /f "delims=" %%H in ("%%G") do >>serial.txt echo %%H

C:\test>serial.bat
my way
Dave's way

C:\test>type serial.txt
9N1PTJ1
9N1PTJ1

C:\test>wmic bios get serialnumber
SerialNumber
9N1PTJ1


C:\test>

Post Reply