patadrian

New Member
Joined
Apr 26, 2011
Messages
6
Hi all! 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.
 

Solution
To retrieve the rotation speed of a disk in a computer using VC++, you can use the Windows Management Instrumentation (WMI) API to query disk information. However, it's worth noting that SSDs (Solid State Drives) do not have a physical disk that spins, so they don't have a rotation speed. If you're specifically looking to identify SSD drives based on the absence of rotation speed, you may need to consider alternative methods like querying the drive type directly from the system. Here's an example code snippet in VC++ that demonstrates how you can use WMI to retrieve disk information and filter out SSD drives based on rotation speed:
C++:
#include #include #include #include # pragma comment(lib, "wbemuuid.lib") int main() { HRESULT hres...
To retrieve the rotation speed of a disk in a computer using VC++, you can use the Windows Management Instrumentation (WMI) API to query disk information. However, it's worth noting that SSDs (Solid State Drives) do not have a physical disk that spins, so they don't have a rotation speed. If you're specifically looking to identify SSD drives based on the absence of rotation speed, you may need to consider alternative methods like querying the drive type directly from the system. Here's an example code snippet in VC++ that demonstrates how you can use WMI to retrieve disk information and filter out SSD drives based on rotation speed:
C++:
#include #include #include #include # pragma comment(lib, "wbemuuid.lib") int main() { HRESULT hres; // Step 1: Initialize COM hres = CoInitializeEx(0, COINIT_APARTMENTTHREADED); if (FAILED(hres)) { std::cerr / Step 2: Initialize WMI hres = CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL ); if (FAILED(hres)) { std::cerr / Step 3: Connect to WMI IWbemLocator* pLoc = NULL; hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc ); if (FAILED(hres)) { std::cerr / Step 4: Connect to the root\cimv2 namespace IWbemServices* pSvc = NULL; hres = pLoc->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pSvc ); if (FAILED(hres)) { std::cerr Release(); CoUninitialize(); return 1; } std::cout / Query WMI for disk information IEnumWbemClassObject* pEnumerator = NULL; hres = pSvc->ExecQuery( _bstr_t("WQL"), _bstr_t("SELECT * FROM Win32_DiskDrive"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator ); if (FAILED(hres)) { std::cerr Release(); pLoc->Release(); CoUninitialize(); return 1; } // Step 5: Iterate over the query results if (pEnumerator) { IWbemClassObject* pclsObj = NULL; ULONG uReturn = 0; while (pEnumerator) { // Code for iterating over the disk drives and retrieving properties // Check the 'RotationSpeed' property to determine if the disk is an SSD // SSDs typically have a 'RotationSpeed' of 0 pclsObj->Release(); } pEnumerator->Release(); } // Cleanup pSvc->Release(); pLoc->Release(); CoUninitialize(); return 0; }
In the code snippet above, make sure to add error handling and proper release of resources in a real-world application. Also, remember that the absence of a rotation speed value can indicate an SSD. This code provides a basic outline and would need to be extended to fit your specific requirements.
 

Solution
Back
Top