diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index ddd12d6ebcb..466611721ab 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -44,6 +44,7 @@ #include "ntsecapi.h" #include "winspool.h" #include "setupapi.h" +#include "ntddstor.h" #include "wine/asm.h" #include "wine/debug.h" @@ -140,7 +141,7 @@ static const struct column col_diskdrive[] = { L"MediaType", CIM_STRING }, { L"Model", CIM_STRING }, { L"PNPDeviceID", CIM_STRING }, - { L"SerialNumber", CIM_STRING }, + { L"SerialNumber", CIM_STRING|COL_FLAG_DYNAMIC }, { L"Size", CIM_UINT64 }, }; static const struct column col_diskdrivetodiskpartition[] = @@ -2081,6 +2082,42 @@ static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize ) } return free.QuadPart; } +static WCHAR *get_diskdrive_serialnumber( WCHAR letter ) +{ + WCHAR *ret = NULL; + STORAGE_DEVICE_DESCRIPTOR *desc; + HANDLE handle = INVALID_HANDLE_VALUE; + STORAGE_PROPERTY_QUERY query = {0}; + WCHAR drive[7]; + DWORD size; + + swprintf( drive, ARRAY_SIZE(drive), L"\\\\.\\%c:", letter ); + handle = CreateFileW( drive, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); + if (handle == INVALID_HANDLE_VALUE) goto done; + + query.PropertyId = StorageDeviceProperty; + query.QueryType = PropertyStandardQuery; + + size = sizeof(*desc) + 256; + for (;;) + { + if (!(desc = heap_alloc( size ))) break; + if (DeviceIoControl( handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), desc, size, NULL, NULL )) + { + if (desc->SerialNumberOffset) ret = heap_strdupAW( (const char *)desc + desc->SerialNumberOffset ); + heap_free( desc ); + break; + } + heap_free( desc ); + if (GetLastError() == ERROR_MORE_DATA) size = desc->Size; + else break; + } + +done: + if (handle != INVALID_HANDLE_VALUE) CloseHandle( handle ); + if (!ret) ret = heap_strdupW( L"WINEHDISK" ); + return ret; +} static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond ) { @@ -2114,7 +2151,7 @@ static enum fill_status fill_diskdrive( struct table *table, const struct expr * rec->mediatype = (type == DRIVE_FIXED) ? L"Fixed hard disk" : L"Removable media"; rec->model = L"Wine Disk Drive"; rec->pnpdevice_id = L"IDE\\Disk\\VEN_WINE"; - rec->serialnumber = L"WINEHDISK"; + rec->serialnumber = get_diskdrive_serialnumber( root[0] ); get_freespace( root, &size ); rec->size = size; if (!match_row( table, row, cond, &status )) diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c index a9b4910ebfa..578e9308df7 100644 --- a/dlls/wbemprox/tests/query.c +++ b/dlls/wbemprox/tests/query.c @@ -1456,6 +1456,31 @@ static void test_Win32_DesktopMonitor( IWbemServices *services ) SysFreeString( wql ); } +static void test_Win32_DiskDrive( IWbemServices *services ) +{ + BSTR wql = SysAllocString( L"wql" ), query = SysAllocString( L"SELECT * FROM Win32_DiskDrive" ); + IEnumWbemClassObject *result; + IWbemClassObject *obj; + HRESULT hr; + DWORD count; + + hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result ); + ok( hr == S_OK, "got %08x\n", hr ); + + for (;;) + { + hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count ); + if (hr != S_OK) break; + + check_property( obj, L"DeviceID", VT_BSTR, CIM_STRING ); + IWbemClassObject_Release( obj ); + } + + IEnumWbemClassObject_Release( result ); + SysFreeString( query ); + SysFreeString( wql ); +} + static void test_Win32_DisplayControllerConfiguration( IWbemServices *services ) { BSTR wql = SysAllocString( L"wql" ); @@ -1561,6 +1586,7 @@ START_TEST(query) test_Win32_ComputerSystemProduct( services ); test_Win32_Bios( services ); test_Win32_DesktopMonitor( services ); + test_Win32_DiskDrive( services ); test_Win32_DisplayControllerConfiguration( services ); test_Win32_IP4RouteTable( services ); test_Win32_OperatingSystem( services );