wmic comand in cmd
Moderator: DosItHelp
wmic comand in cmd
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.
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.
Re: wmic comand in cmd
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
Re: wmic comand in cmd
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
Re: wmic comand in cmd
Which code did you try?
Re: wmic comand in cmd
i tried the two codes :s im under windows 7
Re: wmic comand in cmd
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.
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
Re: wmic comand in cmd
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"
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"
Re: wmic comand in cmd
What did the code I provide give you?
Re: wmic comand in cmd
My code was Tested on Windows 7.
Re: wmic comand in cmd
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
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
Re: wmic comand in cmd
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?
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.
Re: wmic comand in cmd
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!
Re: wmic comand in cmd
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.
Re: wmic comand in cmd
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
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
Re: wmic comand in cmd
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>