I added a new test method, please tell me if I should merge that into an existing one, but as far as I understood, there is no tests for the querying yet.
-- v2: wbemprox: Add property "ExecutablePath" to Win32_Process
From: Fabian Maurer dark.shadow4@web.de
--- dlls/wbemprox/tests/query.c | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c index ea108e31e49..4b3b8f544a8 100644 --- a/dlls/wbemprox/tests/query.c +++ b/dlls/wbemprox/tests/query.c @@ -769,6 +769,53 @@ static void test_Win32_Process( IWbemServices *services, BOOL use_full_path ) IWbemClassObject_Release( out ); }
+static void test_Win32_Process_query( IWbemServices *services ) +{ + WCHAR query_buffer[100]; + WCHAR executable_path[255]; + BSTR wql = SysAllocString( L"wql" ), query; + HRESULT hr; + IEnumWbemClassObject *result; + IWbemClassObject *obj; + DWORD count; + VARIANT value; + CIMTYPE type; + + wsprintfW( query_buffer, L"SELECT * FROM Win32_Process WHERE ProcessId = %lu\n", GetCurrentProcessId() ); + query = SysAllocString( query_buffer); + + hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result ); + if (hr != S_OK) + { + win_skip( "Win32_Process not available\n" ); + goto out; + } + + GetModuleFileNameW( NULL, executable_path, ARRAY_SIZE(executable_path) ); + + hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count ); + ok( hr == S_OK, "got %#lx\n", hr ); + + type = 0xdeadbeef; + VariantInit( &value ); + hr = IWbemClassObject_Get( obj, L"ExecutablePath", 0, &value, &type, NULL ); + todo_wine + ok( hr == S_OK, "IWbemClassObject_Get failed with %#lx\n", hr ); + todo_wine + ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) ); + todo_wine + ok( type == CIM_STRING, "unexpected type %#lx\n", type ); + todo_wine + ok( !lstrcmpiW( V_BSTR( &value ), executable_path), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(executable_path) ); + VariantClear( &value ); + + IWbemClassObject_Release( obj ); + IEnumWbemClassObject_Release( result ); +out: + SysFreeString( wql ); + SysFreeString( query ); +} + static void test_Win32_ComputerSystem( IWbemServices *services ) { BSTR wql = SysAllocString( L"wql" ), query = SysAllocString( L"SELECT * FROM Win32_ComputerSystem" ); @@ -2477,6 +2524,7 @@ START_TEST(query) test_Win32_Printer( services ); test_Win32_Process( services, FALSE ); test_Win32_Process( services, TRUE ); + test_Win32_Process_query( services ); test_Win32_Processor( services ); test_Win32_QuickFixEngineering( services ); test_Win32_Service( services );
From: Fabian Maurer dark.shadow4@web.de
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57314 --- dlls/wbemprox/builtin.c | 17 +++++++++++++++++ dlls/wbemprox/tests/query.c | 4 ---- 2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index 80434e5f19f..d628070dc0b 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -323,6 +323,7 @@ static const struct column col_process[] = { L"Caption", CIM_STRING|COL_FLAG_DYNAMIC }, { L"CommandLine", CIM_STRING|COL_FLAG_DYNAMIC }, { L"Description", CIM_STRING|COL_FLAG_DYNAMIC }, + { L"ExecutablePath", CIM_STRING|COL_FLAG_DYNAMIC }, { L"Handle", CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }, { L"Name", CIM_STRING|COL_FLAG_DYNAMIC }, { L"ParentProcessID", CIM_UINT32 }, @@ -815,6 +816,7 @@ struct record_process const WCHAR *caption; const WCHAR *commandline; const WCHAR *description; + const WCHAR *executablepath; const WCHAR *handle; const WCHAR *name; UINT32 pprocess_id; @@ -3368,6 +3370,9 @@ static enum fill_status fill_process( struct table *table, const struct expr *co HANDLE snap; enum fill_status status = FILL_STATUS_FAILED; UINT row = 0, offset = 0; + HANDLE process; + WCHAR executable_path[MAX_PATH]; + DWORD size;
snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED; @@ -3384,10 +3389,21 @@ static enum fill_status fill_process( struct table *table, const struct expr *co goto done; }
+ process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, entry.th32ProcessID); + if (!process) + { + ERR("Failed to open process\n"); + status = FILL_STATUS_FAILED; + goto done; + } + size = ARRAY_SIZE(executable_path); + QueryFullProcessImageNameW(process, 0, executable_path, &size); + rec = (struct record_process *)(table->data + offset); rec->caption = wcsdup( entry.szExeFile ); rec->commandline = get_cmdline( entry.th32ProcessID ); rec->description = wcsdup( entry.szExeFile ); + rec->executablepath = wcsdup( executable_path ); swprintf( handle, ARRAY_SIZE( handle ), L"%u", entry.th32ProcessID ); rec->handle = wcsdup( handle ); rec->name = wcsdup( entry.szExeFile ); @@ -3397,6 +3413,7 @@ static enum fill_status fill_process( struct table *table, const struct expr *co /* methods */ rec->create = process_create; rec->get_owner = process_get_owner; + CloseHandle(process); if (!match_row( table, row, cond, &status )) { free_row_values( table, row ); diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c index 4b3b8f544a8..f99daaceae9 100644 --- a/dlls/wbemprox/tests/query.c +++ b/dlls/wbemprox/tests/query.c @@ -799,13 +799,9 @@ static void test_Win32_Process_query( IWbemServices *services ) type = 0xdeadbeef; VariantInit( &value ); hr = IWbemClassObject_Get( obj, L"ExecutablePath", 0, &value, &type, NULL ); - todo_wine ok( hr == S_OK, "IWbemClassObject_Get failed with %#lx\n", hr ); - todo_wine ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) ); - todo_wine ok( type == CIM_STRING, "unexpected type %#lx\n", type ); - todo_wine ok( !lstrcmpiW( V_BSTR( &value ), executable_path), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(executable_path) ); VariantClear( &value );
Hans Leidekker (@hans) commented about dlls/wbemprox/tests/query.c:
IWbemClassObject_Release( out );
}
+static void test_Win32_Process_query( IWbemServices *services ) +{
- WCHAR query_buffer[100];
- WCHAR executable_path[255];
- BSTR wql = SysAllocString( L"wql" ), query;
- HRESULT hr;
Please merge this test with test_Win32_Process().
Hans Leidekker (@hans) commented about dlls/wbemprox/builtin.c:
goto done; }
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, entry.th32ProcessID);
if (!process)
{
ERR("Failed to open process\n");
status = FILL_STATUS_FAILED;
goto done;
}
size = ARRAY_SIZE(executable_path);
QueryFullProcessImageNameW(process, 0, executable_path, &size);
Please add a get_executablepath() helper and allocate the path dynamically.