using delphi 7, on windows >= xp, how can retrieve disk signature of every disk computer? preferably without using wmi or diskpart.
and if it's possible, fast too..
thank you.
later edit:
documentation: http://pcsupport.about.com/od/termsd/g/disk-signature.htm mbr disks: http://diddy.boot-land.net/firadisk/files/signature.htm gpt disks: http://thestarman.pcministry.com/asm/mbr/gpt.htm how diskpart (method found on google when searching "disk signature"): diskpart >> list disk >> select disk [n] >> detail disk >> disk id: 0e35445b mbr disks , guid: 55fd03f2-6b11-49df-8167-d30b94a4509d gpt disks
you can use deviceiocontrol
, ioctl_disk_get_drive_layout_ex
obtain information require.
program disksignatureguid; {$apptype console} uses sysutils, windows; type tdrivelayoutinformationmbr = record signature: dword; end; tdrivelayoutinformationgpt = record diskid: tguid; startingusableoffset: int64; usablelength: int64; maxpartitioncount: dword; end; tpartitioninformationmbr = record partitiontype: byte; bootindicator: boolean; recognizedpartition: boolean; hiddensectors: dword; end; tpartitioninformationgpt = record partitiontype: tguid; partitionid: tguid; attributes: int64; name: array [0..35] of widechar; end; tpartitioninformationex = record partitionstyle: integer; startingoffset: int64; partitionlength: int64; partitionnumber: dword; rewritepartition: boolean; case integer of 0: (mbr: tpartitioninformationmbr); 1: (gpt: tpartitioninformationgpt); end; tdrivelayoutinformationex = record partitionstyle: dword; partitioncount: dword; drivelayoutinformation: record case integer of 0: (mbr: tdrivelayoutinformationmbr); 1: (gpt: tdrivelayoutinformationgpt); end; partitionentry: array [0..15] of tpartitioninformationgpt; //hard-coded maximum of 16 partitions end; const partition_style_mbr = 0; partition_style_gpt = 1; partition_style_raw = 2; const ioctl_disk_get_drive_layout_ex = $00070050; procedure main; const // max number of drives assuming primary/secondary, master/slave topology max_ide_drives = 16; var i: integer; drive: string; hdevice: thandle; drivelayoutinfo: tdrivelayoutinformationex; bytesreturned: dword; begin := 0 max_ide_drives - 1 begin drive := '\\.\physicaldrive' + inttostr(i); hdevice := createfile(pchar(drive), 0, file_share_read or file_share_write, nil, open_existing, 0, 0); if hdevice <> invalid_handle_value begin if deviceiocontrol(hdevice, ioctl_disk_get_drive_layout_ex, nil, 0, @drivelayoutinfo, sizeof(drivelayoutinfo), bytesreturned, nil) begin case drivelayoutinfo.partitionstyle of partition_style_mbr: writeln(drive + ', mbr, ' + inttohex(drivelayoutinfo.drivelayoutinformation.mbr.signature, 8)); partition_style_gpt: writeln(drive + ', gpt, ' + guidtostring(drivelayoutinfo.drivelayoutinformation.gpt.diskid)); partition_style_raw: writeln(drive + ', raw'); end; end; closehandle(hdevice); end; end; end; begin main; readln; end.
note since 0
passed dwdesiredaccess
parameter of createfile
, elevated rights not required. explained, albeit opaquely, in documentation:
direct access disk or volume restricted ... following requirements must met such call succeed:
- the caller must have administrative privileges.
- the dwcreationdisposition parameter must have open_existingflag.
- when opening volume or floppy disk, dwsharemode parameter must have file_share_writeflag.
note dwdesiredaccess parameter can zero, allowing application query device attributes without accessing device. useful application determine size of floppy disk drive , formats supports without requiring floppy disk in drive, instance. can used reading statistics without requiring higher-level data read/write permission.
Comments
Post a Comment