Im not really good at VC++ but does anyone have a sample code to get the rotation speed of disk in a computer. I have been working on detecting SSD drives and one solution from researching all day was to get the rotation speed and since SSD have 0 rpm this开发者_开发知识库 might be the only way to detect SSD drive.
From google wmi ssd detect
There is an NV cache manager interface used for ReadyDrive which is new to Vista. I think it is testing NV_FEATURE_PARAMETER's NVReadSpeed and NVWrtSpeed values.
Windows 7 detects SSDs by using ATA8-ACS identify word 217: Nominal media rotation rate, with value 0001h as Non-rotating media like solid state devices. But not all SSDs adhere to the ATA8-ACS1 spec section 7.16.7.77, some may need firmware updates.
If you want to lean more about sending ATA commands in Windows, I suggest you to dig aound the Storage Platform ATA forum. This forum is being archived so act quickly.
Also very enlightening:
http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx
Will disk defragmentation be disabled by default on SSDs?
Yes. The automatic scheduling of defragmentation will exclude partitions on devices that declare themselves as SSDs. Additionally, if the system disk has random read performance characteristics above the threshold of 8 MB/sec, then it too will be excluded. The threshold was determined by internal analysis.
You are likely better off looking for the TRIM command.
BOOL IsDriveSSD(){
DWORD dwBytesReturned;
HANDLE volhand = INVALID_HANDLE_VALUE;
try{
volhand = CreateFile("\\\\.\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
catch(...){
volhand = INVALID_HANDLE_VALUE;
}
if (volhand == INVALID_HANDLE_VALUE) return FALSE;
// Test 1: See if we have a TRIM command, if so, we're SSD.
STORAGE_PROPERTY_QUERY spq;
DEVICE_TRIM_DESCRIPTOR dtr;
memset(&dtr,0,sizeof(DEVICE_TRIM_DESCRIPTOR));
memset(&spq,0,sizeof(STORAGE_PROPERTY_QUERY));
spq.PropertyId=StorageDeviceTrimProperty;
spq.QueryType=PropertyStandardQuery;
BOOL ret = DeviceIoControl(volhand, IOCTL_STORAGE_QUERY_PROPERTY,
&spq,sizeof(spq),
&dtr,sizeof(dtr),
&dwBytesReturned,FALSE);
if(ret){
ret = dtr.TrimEnabled;
}
CloseHandle(volhand);
return ret;
}
I know this is an old thread but this will work on Windows 10
ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk");
scope.Connect();
searcher.Scope = scope;
string type = "";
foreach (ManagementObject queryObj in searcher.Get())
{
switch (Convert.ToInt16(queryObj["MediaType"]))
{
case 1:
type = "Unspecified";
break;
case 3:
type = "HDD";
break;
case 4:
type = "SSD";
break;
case 5:
type = "SCM";
break;
default:
type = "Unspecified";
break;
}
}
searcher.Dispose();
精彩评论