Win32_Diskdrive Serial Number

Posted on by admin
I was just working on this and I thought I would share it with everyone...

Without win32diskdrive serial number hdd hard c# hard-drive What are the correct version numbers for C#? How do I get a consistent byte representation of strings in C# without manually specifying an encoding? Feb 04, 2018  WMI - win32diskdrive gives serial number of 000020. Castorix31 method gives serial number of 000021. Looking in Device Manager and packaging gives serial number of 000026. Definitely something about. Nov 01, 2010  I have used the code from some posts here that use WMI querying Win32DiskDrive SerialNumber to get the manufacturer's serial number. On a Windows 7 laptop, I get SOK status and a 40 byte string starting with '202020' followed by 24 characters 0-9, A-F - a legal hex string for 20 chars??? I wanted to see what Vista says.

One customer asked about getting the serial numbers of USB Storage Devices... Based on some quick research, I came up with:
following texts of lasts ' of preceding texts of lasts '&' of string values whose (it as lowercase starts with 'usbstor') of selects 'PNPDeviceID FROM Win32_DiskDrive' of wmi
I tested this on XP and Vista for 3 different drives (old, sorta new, very new) and it seemed to work well in these cases, but I recommend you test in your own environments.
Additionally, if you were looking to compare the last few digits of the serial number to see if they were in a specific range, (like maybe check if the last 6 digits were between 910000 and 920000) you could do something like this:

Win32_diskdrive Serial Number


Win32 serial communicationWin32 c++ hard drive serial numberq: (it > 910000 AND it < 920000) of (last 6 of it as integer) of following texts of lasts ' of preceding texts of lasts '&' of string values whose (it as lowercase starts with 'usbstor') of selects 'PNPDeviceID FROM Win32_DiskDrive' of wmi
A: True

Here is someone's reference page with some information about querying serial numbers from USB devices if you want more background: http://home.hot.rr.com/graye/Articles/USB_SerialNumbers.htm
Ben
Posted by5 years ago
Archived

Im trying to get the Serial Numbers of any Hard Drives in a desktop as part of a Hardware Inventory script but it is always pulling these weird numbers that arent the SN. this only happens inside the script though. I allocated 'Get-WmiObject win32_DickDrive -computer $strComputer' to a variable called $computerHDD and can pull any information except the SN. if I use the $computerHDD.SerialNumber outside of the script I get the proper SN but when it is in the Script is pulls a different number every time. the full script is below if you want to try to run it.

Win32 Serial Number

EDIT:The issue has been 'fixed' I have to use the WMI class 'Win32_PhysicalMedia' and run it as administrator to get it to work. Thank you all for your help!

Also Thanks to /u/Rankath1 for telling me it is a well known bug and making me relize that I should run as admin.

24 comments