こんにちは、誰かがドライブ/ハードウェアの名前を取得する方法を手伝ってくれませんか/ / 'C: \' 'D: \' .......
例
NameDrive function (const sDrive: string): string;
begin
result: = GetDriveName (sDrive);
end;
Showmessage (NameDrive ('C: \')) / / = ST500DM0 ....
清聴ありがとうございました。
IOCTL_STORAGE_QUERY_PROPERTY コード (STORAGE_PROPERTY_QUERY PropertyId を StorageDeviceProperty に設定) を使用して DeviceIoControl を呼び出すか、SMART_ 制御コードを使用して DeviceIoControl を呼び出すか、WMI データを読み取ることで、ベンダー情報を取得できます。いずれにしても、論理ドライブではなく \.\PhysicalDriveX のような名前の物理ドライブを使用する必要があります。これらは、私が一度に見ることができる 3 つの選択肢です。
方法 1 の例 (DDK から取得した型定義):
type
STORAGE_PROPERTY_ID = (
StorageDeviceProperty,
StorageAdapterProperty,
StorageDeviceIdProperty,
StorageDeviceUniqueIdProperty, // See storduid.h for details
StorageDeviceWriteCacheProperty,
StorageMiniportProperty,
StorageAccessAlignmentProperty,
StorageDeviceSeekPenaltyProperty,
StorageDeviceTrimProperty,
StorageDeviceWriteAggregationProperty
);
STORAGE_QUERY_TYPE = (
PropertyStandardQuery, // Retrieves the descriptor
PropertyExistsQuery, // Used to test whether the descriptor is supported
PropertyMaskQuery, // Used to retrieve a mask of writeable fields in the descriptor
PropertyQueryMaxDefined // use to validate the value
);
STORAGE_PROPERTY_QUERY = packed record
PropertyId, // ID of the property being retrieved
QueryType : Cardinal; // Flags indicating the type of query being performed
AdditionalParameters : array [0..0] of AnsiChar; // Space for 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, i : 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 then
begin
FreeMemory(buf);
Exit;
end;
PropResponse := (PSTORAGE_DEVICE_DESCRIPTOR(Buf))^;
if PropResponse.RawPropertiesLength <> 0 then
begin
aModel := '';
if PropResponse.VendorIdOffset <> 0 then
begin
i := PropResponse.VendorIdOffset;
while Buf[i] <> 0 do
begin
aModel := aModel + AnsiChar(Buf[i]);
Inc(i);
end;
end;
if PropResponse.ProductIdOffset <> 0 then
begin
aModel := aModel + ' ';
i := PropResponse.ProductIdOffset;
while Buf[i] <> 0 do
begin
aModel := aModel + AnsiChar(Buf[i]);
Inc(i);
end;
end;
end;
FreeMemory(buf);
end;
ドライブは次の方法で開く必要があります。
Result := CreateFile(PWideChar(DrvName), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
ここで、DrvName は、たとえば、システムの最初のドライブの \\.\PhysicalDrive0 です。一般的に言えば、単一のボリューム、たとえば D:\ が複数の物理ディスクにまたがる動的なボリュームである可能性があるため、希望どおりに正確に実行することはできません。