pafish/pafish/utils.c
int wmi_initialize(const wchar_t *query_namespace, IWbemServices **services) {
	BSTR namespace;
	IWbemLocator *locator = NULL;
	int result;

	HRESULT hresult = CoInitializeEx(0, COINIT_MULTITHREADED);

	if (FAILED(hresult)) {
		return FALSE;
	}

	hresult = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
		RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

	if (FAILED(hresult)) {
		CoUninitialize();

		return FALSE;
	}

	hresult = CoCreateInstance(&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
		&IID_IWbemLocator, (LPVOID *) & locator);

	if (FAILED(hresult)) {
		CoUninitialize();

		return FALSE;
	}

	namespace = SysAllocString(query_namespace);

	// Connect to the namespace with the current user and obtain pointer
	// services to make IWbemServices calls.
	hresult = locator->lpVtbl->ConnectServer(locator, namespace, NULL, NULL, NULL, 0,
		NULL, NULL, services);

	result = FAILED(hresult) ? FALSE : TRUE;

	SysFreeString(namespace);
	locator->lpVtbl->Release(locator);

	return result;
}
/**
 * Initialise the WMI client that will connect to the local machine WMI
 * namespace. It will return TRUE if the connection was successful, FALSE
 * otherwise.
 */
Initialise the WMI client that will connect to the local machine WMI
namespace. It will return TRUE if the connection was successful, FALSE
otherwise.
Initialise the WMI client that will connect to the local machine WMI namespace . It will return TRUE if the connection was successful FALSE otherwise .
int wmi_initialize(const wchar_t *query_namespace, IWbemServices **services) {
	BSTR namespace;
	IWbemLocator *locator = NULL;
	int result;
	HRESULT hresult = CoInitializeEx(0, COINIT_MULTITHREADED);
	if (FAILED(hresult)) {
		return FALSE;
	}
	hresult = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
		RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
	if (FAILED(hresult)) {
		CoUninitialize();
		return FALSE;
	}
	hresult = CoCreateInstance(&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
		&IID_IWbemLocator, (LPVOID *) & locator);
	if (FAILED(hresult)) {
		CoUninitialize();
		return FALSE;
	}
	namespace = SysAllocString(query_namespace);
	hresult = locator->lpVtbl->ConnectServer(locator, namespace, NULL, NULL, NULL, 0,
		NULL, NULL, services);
	result = FAILED(hresult) ? FALSE : TRUE;
	SysFreeString(namespace);
	locator->lpVtbl->Release(locator);
	return result;
}
int wmi_initialize ( const wchar_t * query_namespace , IWbemServices * * services ) { BSTR namespace ; IWbemLocator * locator = NULL ; int result ; HRESULT hresult = CoInitializeEx ( 0 , COINIT_MULTITHREADED ) ; if ( FAILED ( hresult ) ) { return FALSE ; } hresult = CoInitializeSecurity ( NULL , -1 , NULL , NULL , RPC_C_AUTHN_LEVEL_DEFAULT , RPC_C_IMP_LEVEL_IMPERSONATE , NULL , EOAC_NONE , NULL ) ; if ( FAILED ( hresult ) ) { CoUninitialize ( ) ; return FALSE ; } hresult = CoCreateInstance ( & CLSID_WbemLocator , 0 , CLSCTX_INPROC_SERVER , & IID_IWbemLocator , ( LPVOID * ) & locator ) ; if ( FAILED ( hresult ) ) { CoUninitialize ( ) ; return FALSE ; } namespace = SysAllocString ( query_namespace ) ; hresult = locator -> lpVtbl -> ConnectServer ( locator , namespace , NULL , NULL , NULL , 0 , NULL , NULL , services ) ; result = FAILED ( hresult ) ? FALSE : TRUE ; SysFreeString ( namespace ) ; locator -> lpVtbl -> Release ( locator ) ; return result ; }
Initialise the WMI client that will connect to the local machine WMI
 namespace.
Initialise the WMI client that will connect to the local machine WMI namespace .
// Connect to the namespace with the current user and obtain pointer // services to make IWbemServices calls.