Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From the Windows NT-based (Windows XP and 7 specifically) command prompt, how can I get the serial number of a hard drive as a variable? The one I'm looking at is the serial number of the physical hard disk drive

share|improve this question
For Windows xp, see this question for a proper method: superuser.com/q/708146/24010 –  Canadian Luke Jan 28 '14 at 16:17
If you have many hard drives like me, use this instead to help you know which is which: wmic diskdrive get name,size,model,SerialNumber... Source –  Enissay May 18 '14 at 17:21

3 Answers 3

up vote 23 down vote accepted

Try this command

vol C:

this will get the volume serial number given to it by windows.

wmic diskdrive get serialnumber

this gets the manufacturers serial number of the hard drive.

share|improve this answer
Dude, he is wanting the Volume Number which you get while firing the directory command (at the top), not the hard drive serial key. The command you specified actually gets you the hard drive serial key which is quite long, i believe 40 characters. –  aliasgar Nov 2 '12 at 0:53
I don't see that in his question, maybe he needs to re-word the title dude, "How to get hard drive serial number from command line?" –  Moab Nov 2 '12 at 2:42
When using wmic diskdrive get serialnumber I get the message Invalid XML. What does it mean? –  Maxbester May 27 '13 at 8:00
I get invalid query error for wmic diskdrive get serialnumber. –  atoMerz Feb 10 '14 at 7:49
@Maxbester and @atoMerz: I had both problems. Invalid XML was due to having more than one drive connected and Invalid query occurred because I was on Windows XP. See this answer for both issues: stackoverflow.com/questions/9287450/… –  Matthias Braun Jul 16 '14 at 10:06
  • What you are looking at is NOT the hard drive serial number.

  • It is called the Volume Serial Number. It is generated at the time of creating and formatting the volume / partition.

  • You can get it by using a command at command prompt : C:\> vol c: if C: is the drive you want to retrieve the Volume Serial Number for.

  • All you can do is redirect the output of that command to a file : C:\> vol c: > myvol.txt and it will be stored as a text file in your C:

  • I am attaching a screenshot with the highlights:

enter image description here

  • The file was stored in the root of C:

enter image description here

  • This is what the myvol.txt file looks like in Notepad:

enter image description here

share|improve this answer
Question edited; sorry for the mis-information –  Canadian Luke Nov 2 '12 at 16:39

In a batch file one approach is:

  1. VOL command to produce the serial number as text along with text we don't want.
  2. FIND to trim it down to only the line with the serial number.
  3. FOR to grab the 5th token (a part between delimiters) on the line with the serial number.
  4. SET to assign to an environment variable

for /f "tokens=5 delims= " %%a in ('vol c: ^| Find "Serial Number"') do (
share|improve this answer
Question edited; sorry for the mis-information –  Canadian Luke Nov 2 '12 at 16:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.