
Get Hard Drive Serial Number Delphi
Your code is not working because you are passing a double-quote in the WMI class name. Change this code GetWMIstring(','Win32_DiskDrive','SerialNumber'); To this GetWMIstring(','Win32_DiskDrive','SerialNumber'); Btw, you can improve a lot your WMI function (GetWMIstring) if you follow the recommendations of the answer to this question.
Recognize a HDD serial number • Drives • Examples for Delphi with complete source codes. I'm trying to read serial no of the hard disk as a unique id of the machine. IrDriveRegs: TIDERegs; // Physical drive number to send command to (0,1,2,3). I built the code segment by using Delphi XE 7 and tested it on my Lenovo. But if you prefer you can take a look on the source code and get all the.
You should avoid, when more devices installed, PHYSICALDRIVE0 doesn't need to be first in database. Akt vipolnennih rabot ks2 blank kazahstan. PHYSICALDRIVE1 is first by me.
I added where to query and it is working OK now. For Win32_DiskDrive is property name DeviceID, for Win32_PhysicalDrive is property name Tag. Here changed part: function GetWMIstring(const WMIClass, WMIProperty, WMIWhere:string): string. Qry:='SELECT '+WMIProperty+' FROM '+WMIClass; if WMIWhere' then qry:=qry + ' WHERE '+WMIWhere; FWbemObjectSet:= FWMIService.ExecQuery(qry,'WQL',wbemFlagForwardOnly). PHYSICALDRIVE0')); y:=GetWMIstring('Win32_PhysicalMedia','SerialNumber','Tag='.
PHYSICALDRIVE0')); / Dont forget to Call CoInitialize before!!!
This isn't possible or practical for all hardware. Every RAID controller has vendor-specific APIs, and not all controllers even have the intelligence or architecture to facilitate pass-through commands to get to the disks. Now getting JBOD is a different thing entirely,. But it is a lot of work (I know, I've done it, plus have support for maybe a dozen RAID controllers).
But this would still require thousands of hours of development time. ATA/IDE/SATA uses one family of IOCTLS, and is easiest, but WinME/Win9x uses different code from WInNT/2K' same source code can be used between win 2k/2k3/2k8, but Vista/Win7 needs to be a little different; SCSI/SAS/FC/USB-attached uses SCSI command-set. ATA/SATA/IDE uses ATA command-set. But even on JBOD, SATA disks may use SCSI command-set depending on the motherboard & controller. The location of serial numbers is standardized for disks that speak the native ATA commands, but the SCSI spec allows serial numbers to be in one of several places, so you have to go through a list of a dozen places.
Also if you are using 64-bit O/S then pass-through commands don't work properly, so you have to make sure your source code compiles. So just forget this project, the best you can do is read serial numbers from the registry, but all anybody has to do is change the registry entry and the info is not valid. Also in many cases, depending on the specific O/S & hardware config, the registry entries are also wrong. I response to the other advice 1) Retrieving the volume serial number is useless, as this can be changed any time via the registry 2) The ReadHDD seriial # logic is CORRECT. However it is only valid for ATA/SATA, but this IOCTL will not work for WinMe -> Win7. MSFT has other IOCTLs, depending on what O/S you have.
Also the IOCTL will break for a SAS+SATA controller, and SCSI, FC, SAS controllers. It only deals with the ATA command0set The IDE link includes other code for the older MS O/Ss, but it still won't help with anything but a direct-connect non-RAID ATA/IDE drive. It also has same constraints I mentioned before. SATA is where it starts to get difficult, because you have to use different pass-through code depending on whether the disk is emulating an IDE disk using the ATA instruction set, or if it is attached to a SAS/SATA controller; or a RAID controller in non-RAID mode, or RAID controller in RAID mode. If RAID controller, then it is vendor specific. Beyond that, if it is attached to a SAS/SATA controller you have to 'speak' SCSI commands to it, and encapsulate SATA commands, which may be 12 or 16 bytes long, depending on controller.