C++ HDD Serial Number
-
I want to know how to find the HDD Serial Number from using C++ or C or any assembly code. Thanks, Anwar.
This one might help you[^] SaRath.
"Don't Do Different things... Do Things Differently..." Understanding State Pattern in C++ -
I want to know how to find the HDD Serial Number from using C++ or C or any assembly code. Thanks, Anwar.
anwar1026 wrote:
I want to know how to find the HDD Serial Number from using C++ or C or any assembly code.
Check GetVolumeInformation() API where you get the information of the volume serial number in lpVolumeSerialNumber parameter. Here you get more information[^] Knock out 't' from can't, You can if you think you can :cool: -- modified at 8:01 Friday 9th June, 2006
-
I want to know how to find the HDD Serial Number from using C++ or C or any assembly code. Thanks, Anwar.
If you need volume's serial number (for logical disks C:, D:, etc.), you can use
GetVolumeInformation
function. If you need serial numbers of your hard disks as physical devices, you can follow the famous Windows Management Instrumentation (WMI) way, which does not look so simple:#define _WIN32_WINNT 0x0400 #include <objbase.h> #include <comdef.h> #include <Wbemidl.h> # pragma comment(lib, "wbemuuid.lib") _COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator)); _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices)); _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject)); _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject)); int main() { CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); IWbemLocatorPtr locator; CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *)&locator ); IWbemServicesPtr services; locator->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &services ); IEnumWbemClassObjectPtr enumerator; services->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_DiskDrive"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &enumerator); IWbemClassObjectPtr object = 000; for( ; ; ) { ULONG ret; enumerator->Next(WBEM_INFINITE, 1, &object, &ret); if( ret == 0) break; _variant_t variant; object->Get(L"Caption", 0, &variant, 0, 0); MessageBox(0, _bstr_t(variant), "The serial number is:", MB_OK); } return 0; // // TODO: check any call for errors // }
Hope it helps.
-
If you need volume's serial number (for logical disks C:, D:, etc.), you can use
GetVolumeInformation
function. If you need serial numbers of your hard disks as physical devices, you can follow the famous Windows Management Instrumentation (WMI) way, which does not look so simple:#define _WIN32_WINNT 0x0400 #include <objbase.h> #include <comdef.h> #include <Wbemidl.h> # pragma comment(lib, "wbemuuid.lib") _COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator)); _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices)); _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject)); _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject)); int main() { CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); IWbemLocatorPtr locator; CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *)&locator ); IWbemServicesPtr services; locator->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &services ); IEnumWbemClassObjectPtr enumerator; services->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_DiskDrive"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &enumerator); IWbemClassObjectPtr object = 000; for( ; ; ) { ULONG ret; enumerator->Next(WBEM_INFINITE, 1, &object, &ret); if( ret == 0) break; _variant_t variant; object->Get(L"Caption", 0, &variant, 0, 0); MessageBox(0, _bstr_t(variant), "The serial number is:", MB_OK); } return 0; // // TODO: check any call for errors // }
Hope it helps.
-
The "WbemIdl.h" file is located in "Vc*\PlatformSDK\Include\WbemIdl.h" subdirectory of Visual Studio 2003 or 2005. Are you using another compiler? Or may be you have a reduced variant of Visual Studio. WMI includes more header files, libraries and DLLs. In Windows 98, WMI has to be installed separately. I think you would have to download WMI from Microsoft site.
-
It's part of the Platform SDK.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
The "WbemIdl.h" file is located in "Vc*\PlatformSDK\Include\WbemIdl.h" subdirectory of Visual Studio 2003 or 2005. Are you using another compiler? Or may be you have a reduced variant of Visual Studio. WMI includes more header files, libraries and DLLs. In Windows 98, WMI has to be installed separately. I think you would have to download WMI from Microsoft site.