windows - Get name Drive Hardware -
hello me how name of drive / hardware / / 'c: \' 'd: \' .......
example
namedrive function (const sdrive: string): string; begin result: = getdrivename (sdrive); end; showmessage (namedrive ('c: \')) / / = st500dm0 ....
thank attention.
it's possible vendor info calling deviceiocontrol ioctl_storage_query_property code (storage_property_query propertyid set storagedeviceproperty), or smart_ control codes, or reading wmi data. in case should work physical drives having names \.\physicaldrivex rather logical ones. these 3 alternatives can see @ once.
example of method 1 (type definitions taken ddk):
type storage_property_id = ( storagedeviceproperty, storageadapterproperty, storagedeviceidproperty, storagedeviceuniqueidproperty, // see storduid.h details storagedevicewritecacheproperty, storageminiportproperty, storageaccessalignmentproperty, storagedeviceseekpenaltyproperty, storagedevicetrimproperty, storagedevicewriteaggregationproperty ); storage_query_type = ( propertystandardquery, // retrieves descriptor propertyexistsquery, // used test whether descriptor supported propertymaskquery, // used retrieve mask of writeable fields in descriptor propertyquerymaxdefined // use validate value ); storage_property_query = packed record propertyid, // id of property being retrieved querytype : cardinal; // flags indicating type of query being performed additionalparameters : array [0..0] of ansichar; // space additional parameters if necessary end; storage_device_descriptor = packed record version, size : cardinal; devicetype : byte; devicetypemodifier : byte; removablemedia, commandqueueing : byte; vendoridoffset, productidoffset, productrevisionoffset, serialnumberoffset : cardinal; bustype : cardinal; rawpropertieslength : cardinal; rawdeviceproperties : array [0..0] of ansichar; end; const storage_property_query_size = 12; function getdrivemodel(drvhandle : thandle; var amodel : ansistring; out errcode : integer) : boolean; var propquery : storage_property_query; propresponse : storage_device_descriptor; propresponsesize, : cardinal; buf : pbyte; begin fillchar(propquery, storage_property_query_size, 0); propquery.propertyid := cardinal(storagedeviceproperty); propquery.querytype := cardinal(propertystandardquery); buf := getmemory(4096); result := deviceiocontrol(drvhandle, ioctl_storage_query_property, @propquery, storage_property_query_size, buf, 4096, propresponsesize, nil); errcode := getlasterror; if not result begin freememory(buf); exit; end; propresponse := (pstorage_device_descriptor(buf))^; if propresponse.rawpropertieslength <> 0 begin amodel := ''; if propresponse.vendoridoffset <> 0 begin := propresponse.vendoridoffset; while buf[i] <> 0 begin amodel := amodel + ansichar(buf[i]); inc(i); end; end; if propresponse.productidoffset <> 0 begin amodel := amodel + ' '; := propresponse.productidoffset; while buf[i] <> 0 begin amodel := amodel + ansichar(buf[i]); inc(i); end; end; end; freememory(buf); end;
a drive should opened way:
result := createfile(pwidechar(drvname), generic_read or generic_write, file_share_read or file_share_write, nil, open_existing, 0, 0);
where drvname e.g. \\.\physicaldrive0 1st drive in system. speaking, it's not possible want exactly, because single volume, say, d:\ may dynamic 1 spanning several physical disks.
Comments
Post a Comment