pafish/pafish/utils.c
int wmi_check_query(IWbemServices *services, const wchar_t *language, const wchar_t *query,
		wmi_check_row check_row) {
	int status = FALSE;
	IEnumWbemClassObject *queryrows = NULL;
	BSTR wmilang = SysAllocString(language);
	BSTR wmiquery = SysAllocString(query);

	// Execute the query.
	HRESULT result = services->lpVtbl->ExecQuery(
		services, wmilang, wmiquery, WBEM_FLAG_BIDIRECTIONAL, NULL, &queryrows);

	if (!FAILED(result) && (queryrows != NULL)) {
		IWbemClassObject * batchrows[10];
		ULONG index, count = 0;
		result = WBEM_S_NO_ERROR;

		while (WBEM_S_NO_ERROR == result && status == FALSE) {
			// Retrieve 10 rows (instances) each time.
			result = queryrows->lpVtbl->Next(queryrows, WBEM_INFINITE, 10,
				batchrows, &count);

			if (!SUCCEEDED(result)) {
				continue;
			}

			for (index = 0; index < count && status == FALSE; index++) {
				status = check_row(batchrows[index]);

				batchrows[index]->lpVtbl->Release(batchrows[index]);
			}
		}

		queryrows->lpVtbl->Release(queryrows);
	}

	SysFreeString(wmiquery);
	SysFreeString(wmilang);

	return status;
}
/**
 * Execute the suplied WMI query and call the row checking function for each row returned.
 */
Execute the suplied WMI query and call the row checking function for each row returned.
Execute the suplied WMI query and call the row checking function for each row returned .
int wmi_check_query(IWbemServices *services, const wchar_t *language, const wchar_t *query,
		wmi_check_row check_row) {
	int status = FALSE;
	IEnumWbemClassObject *queryrows = NULL;
	BSTR wmilang = SysAllocString(language);
	BSTR wmiquery = SysAllocString(query);
	HRESULT result = services->lpVtbl->ExecQuery(
		services, wmilang, wmiquery, WBEM_FLAG_BIDIRECTIONAL, NULL, &queryrows);
	if (!FAILED(result) && (queryrows != NULL)) {
		IWbemClassObject * batchrows[10];
		ULONG index, count = 0;
		result = WBEM_S_NO_ERROR;
		while (WBEM_S_NO_ERROR == result && status == FALSE) {
			result = queryrows->lpVtbl->Next(queryrows, WBEM_INFINITE, 10,
				batchrows, &count);
			if (!SUCCEEDED(result)) {
				continue;
			}
			for (index = 0; index < count && status == FALSE; index++) {
				status = check_row(batchrows[index]);
				batchrows[index]->lpVtbl->Release(batchrows[index]);
			}
		}
		queryrows->lpVtbl->Release(queryrows);
	}
	SysFreeString(wmiquery);
	SysFreeString(wmilang);
	return status;
}
int wmi_check_query ( IWbemServices * services , const wchar_t * language , const wchar_t * query , wmi_check_row check_row ) { int status = FALSE ; IEnumWbemClassObject * queryrows = NULL ; BSTR wmilang = SysAllocString ( language ) ; BSTR wmiquery = SysAllocString ( query ) ; HRESULT result = services -> lpVtbl -> ExecQuery ( services , wmilang , wmiquery , WBEM_FLAG_BIDIRECTIONAL , NULL , & queryrows ) ; if ( ! FAILED ( result ) && ( queryrows != NULL ) ) { IWbemClassObject * batchrows [ 10 ] ; ULONG index , count = 0 ; result = WBEM_S_NO_ERROR ; while ( WBEM_S_NO_ERROR == result && status == FALSE ) { result = queryrows -> lpVtbl -> Next ( queryrows , WBEM_INFINITE , 10 , batchrows , & count ) ; if ( ! SUCCEEDED ( result ) ) { continue ; } for ( index = 0 ; index < count && status == FALSE ; index ++ ) { status = check_row ( batchrows [ index ] ) ; batchrows [ index ] -> lpVtbl -> Release ( batchrows [ index ] ) ; } } queryrows -> lpVtbl -> Release ( queryrows ) ; } SysFreeString ( wmiquery ) ; SysFreeString ( wmilang ) ; return status ; }
Execute the suplied WMI query and call the row checking function for each row returned.
Execute the suplied WMI query and call the row checking function for each row returned .
// Execute the query. // Retrieve 10 rows (instances) each time.