Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done Disk name

Jun
46
1
The command

echo %@serial[C:]

shows the "soft" serial of a disk or partition.

But this number can be changed, for example when one does a disk clone
of a disk: you end with two (or more) disk(s) with the same serial.

But the disk serial hardwired by the disk maker is unique.

This number can be obtained, say for disk 0:

wmic diskdrive 0 get serialnumber

For example:

wmic diskdrive 0 get serialnumber S e r i a l N u m b e r

1 7 1 4 2 1 8 0 2 0 3 1

wmic diskdrive 1 get serialnumber S e r i a l N u m b e r

W D - W M C 6 N 0 E 4 6 3 2 T

wmic diskdrive 2 get serialnumber S e r i a l N u m b e r

W D - W C C 4 M 1 L A 9 F L 3

The output of wmic has NULL characters between serial number
characters.

If one must take a option based in disk (hard) serial, it is difficult
to do.

Is it possible to obtain a string without separator, and without the
header "Serial number"?

Thank you.

OPH.
 
I had some luck doing this:
Code:
alias drivenum=`(wmic diskdrive %@eval[0%1] get serialnumber) > x.tmp & tail /n1 x.tmp`
drivenum 0
ADEADBEEF  (<--fake hexadecimal result)
 
wmic diskdrive 0 get serialnumber S e r i a l N u m b e r

1 7 1 4 2 1 8 0 2 0 3 1

wmic diskdrive 1 get serialnumber S e r i a l N u m b e r

W D - W M C 6 N 0 E 4 6 3 2 T

wmic diskdrive 2 get serialnumber S e r i a l N u m b e r

W D - W C C 4 M 1 L A 9 F L 3

The output of wmic has NULL characters between serial number
characters.

Incidentally, this behavior (NULs between spaces) is what you see when you try to read a UTF-16 text file as if it were 8-bit text.
 
Hmmm! Both WMIQUERY and @WMI work when elevated.
Code:
v:\> wmic diskdrive 0 get serialnumber
SerialNumber
2020202020202020202020205239345752375641


v:\> wmiquery root\cimv2 "select serialnumber from win32_diskdrive where index = 0"
2020202020202020202020205239345752375641

v:\> echo %@wmi[root\cimv2,"select serialnumber from win32_diskdrive where index = 0"]
2020202020202020202020205239345752375641

When not elevated, @WMI quietly returns an empty string while WMIQUERY gives a peculiar error message.
Code:
v:\> echo %@wmi[root\cimv2,"select serialnumber from win32_diskdrive where index = 0"]
ECHO is OFF

v:\> wmiquery root\cimv2 "select serialnumber from win32_diskdrive where index = 0"
Error (SYS): Incorrect function.

I wonder how WMIQ.EXE manages to work unelevated.

I also wonder why my output is so ugly compared to oph's.
 
OK, now @WMI and WMIQUERY are working unelevated. And, come to think of it, my outout isn't all that ugly. Al least it doesn't look like Unicode, but it does have all thgose leading "20"s. If I treat the output of WMIC, WMIQUERY, and @WMI as hex and disregard the initial "20"s, it looks nicer.
Code:
v:\> echo %@wmi[root\cimv2,"select serialnumber from win32_diskdrive where index = 0"]
2020202020202020202020205239345752375641

v:\> echo %@char[0x52 0x39 0x34 0x57 0x52 0x37 0x56 0x41]
R94WR7VA
 
I googled some, and found this to be a small nightmare. The serial number is a string, but the manufacturer is free to "encode" the string as he sees fit. And apparently, since there are no rules, Windows can only guess what to do with the string it finds.

I can get the same hex-coded (?) string as before like this (unelevated).
Code:
v:\> echo %@ltrim[" ",%@wmi[root\cimv2,"SELECT SerialNumber FROM Win32_PhysicalMedia where tag = '\\\\.\\PHYSICALDRIVE0'"]]
2020202020202020202020205239345752375641

And I can manually "decode" it like this, taking the bytes in order.
Code:
v:\> do i=0 to 38 by 2 ( set hex=%@instr[%i,2,2020202020202020202020205239345752375641] & if %hex NE 20 echos %@char[0x%hex] )
R94WR7VA

If I do the very same query elevated, watch what happens!
Code:
v:\> echo %@ltrim[" ",%@wmi[root\cimv2,"SELECT SerialNumber FROM Win32_PhysicalMedia where tag = '\\\\.\\PHYSICALDRIVE0'"]]
9RW47RAV

It's decoded for me ... well sort of. Each pair of characters has had it's order switched.

So what is the serial number of that disk?
 
It's decoded for me ... well sort of. Each pair of characters has had it's order switched.
Big-endian ASCII versus little-endian ASCII? :woot:

There ought to be a way to get this info via DeviceIoControl().
 
9RW47RAV

Non-elevated, my drive returns
Code:
echo %@ltrim[" ",%@wmi[root\cimv2,"SELECT SerialNumber FROM Win32_PhysicalMedia where tag = '\\\\.\
\PHYSICALDRIVE0'"]]
W -DXW151CF07810
But Western Digital drive serial numbers start with "WD-" so there's your answer.

Here, it looks good for a WD (elevated or not).
Code:
v:\> echo %@wmi[root\cimv2,"SELECT SerialNumber FROM Win32_PhysicalMedia where tag = '\\\\.\\PHYSICALDRIVE2'"]
WD-WXE508CJ3523

v:\> echo %@wmi[root\cimv2,"select serialnumber from win32_diskdrive where index = 2"]
WD-WXE508CJ3523

v:\> wmic diskdrive 2 get serialnumber
SerialNumber
WD-WXE508CJ3523

What was the answer?
 
HWINFO (it is a free program) serial number agrees with wmic:

wmic diskdrive get serialnumber

S e r i a l N u m b e r

W D - W M C 6 N 0 E 4 6 3 2 T

W D - W C C 4 M 1 L A 9 F L 3

1 7 1 4 2 1 8 0 2 0 3 1

The last disk is a SSD and I have the number accesible: it agrees 171421802031
 

Attachments

  • disco0.pdf
    26.3 KB · Views: 321
  • disco1.pdf
    25.8 KB · Views: 261
  • disco2.pdf
    24 KB · Views: 372
The big question is - for what purpose you are trying to obtain these strings.
Hardware serial is rather useless for OS behavior, for instance.
 

Similar threads

Back
Top