Concerning RAID drives and others:
WMI offers a few different classes for getting the serial number of drives. There are a few different WMI classes that offer up the drive serial number, Win32_DiskDrive and Win32_PhysicalMedia for example.
The SerialNumber property for the Win32_DiskDrive class description says this:
"SerialNumber
Data type: string
Access type: Read-only
Number allocated by the manufacturer to identify the physical media.
Example: WD-WM3493798728
Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0: This property is not available. "
The SerialNumber property for the Win32_PhysicalMedia class description says this:
"SerialNumber
Data type: string
Access type: Read-only
Manufacturer-allocated number used to identify the physical media.
Example: WD-WM3493798728"
So those both are the same in this respect except that one of them can be used in Windows XP and the other can't. Both work in Windows 7, and they worked in Windows Vista also. Heres a quick simple thing using srods COMate for getting the hardware serial numbers of drives using both classes (there are other classes that do this also):
Code: Select all
XIncludeFile "COMatePLUS.pbi"
Procedure DD_Info1()
Define.COMateObject objWMIService, DDInfo
colDDInfo.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colDDInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_PhysicalMedia')")
If colDDInfo
DDInfo = colDDInfo\GetNextObject()
While DDInfo
Debug DDInfo\GetStringProperty("SerialNumber")
DDInfo\Release()
DDInfo = colDDInfo\GetNextObject()
Wend
colDDInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "DDInfo")
EndIf
EndProcedure
Procedure DD_Info2()
Define.COMateObject objWMIService, DDInfo
colDDInfo.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colDDInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_DiskDrive')")
If colDDInfo
DDInfo = colDDInfo\GetNextObject()
While DDInfo
Debug DDInfo\GetStringProperty("SerialNumber")
DDInfo\Release()
DDInfo = colDDInfo\GetNextObject()
Wend
colDDInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "DDInfo")
EndIf
EndProcedure
DD_Info1()
DD_Info2()
Both classes produce the same serial number. I didn't provide any identification for which drive is which so thats up to you. If its a raid drive its serial number is given as RAID in some cases, it does for mine.
Notice they say "Manufacturer serial number" and not "Volume Serial Number" like for for each parition. So these are manufacturer assigned, not user assigned by formatting or partitioning. These should not change. I don't think the manufacturer would go to the trouble of assigning a unique serial number to identify something only for the user to have the ability to change it by something so common as a format or even an operating system install (clean installs of Windows basically performs a format of the drive).
Both descriptions for both classes say "Manufacturer allocated number used to identify the physical media." . As for using this a a protection method, hmmmm...well, lets look at that. If I look up my RAID drive in the windows registry I find this (below is exported from the registry):
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 6\Scsi Bus 0\Target Id 0\Logical Unit Id 0]
"Identifier"="RAID0"
"Type"="DiskPeripheral"
"InquiryData"=hex:00,00,04,02,1f,00,00,00,52,41,49,44,30,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,30,30,30,30
"SerialNumber"="RAID "
"DeviceIdentifierPage"=hex:00,83,00,34,02,01,00,10,31,39,37,42,32,33,36,33,31,\
39,37,42,32,33,36,33,01,02,00,10,31,39,37,42,32,33,36,33,31,39,37,42,32,33,\
36,33,01,03,00,08,20,39,37,42,32,33,36,33
see where it says "SerialNumber"="RAID " ...so personally I would not want to base a software protection that could be overcome by simply getting the serial number from the registry. Some people will say that the hard drive serial numbers that WMI gives are simply from the registry, the only thing that comes close to being in the registry for me for hard drive serial numbers is the RAID drive and it appeared as simply "RAID" for its serial number and this kinda makes sense because I already know that RAID0 striped arrays drives don't have serial numbers if they are RAID0 and my RAID is RAID0, only when the drives in the RAID0 array are no longer in the array can you read a serial number for them. None of the other hard drive (non-raid drives) serial numbers appear in the registry for the rest of the drives on the machine. I'm on Windows 7 Ultimate so there may be something with previous opertaing systems in the registry for serial numbers, I don't remember if there was or not.
But what about non-RAID SATA drives? Yep the above WMI code using COMate gets them. But since i'm focusing manily on RAID here, what about non RAID0 Raid arrays like RAID 5? Take another look at that registry export, the key path - "Scsi\Scsi Port 6\Scsi Bus 0" > ahhhhhh HA! A clue for reading hardware serial numbers for RAID (not RAID0). Everything I can find and read leads back to having to query the Scsi bus and the devices on it to get the actual manufacturer hardware serial numbers of RAID drives. So, can you tell what i'm thinking ?
