WMI

Provides gateway to Windows Management Instrumentation. Written in C++
but its interface is exportable to C code.

NOTE: all unsigned short* arguments accept wide (UNICODE) strings,
because WMI uses them internally, so write L"string" in your code

Constants

HI_WMI_ERROR_INIT_COM, HI_WMI_ERROR_CONNECT, HI_WMI_ERROR_CREATE_LOCATOR, HI_WMI_ERROR_SECURITY, HI_WMI_OK, HI_WMI_ERROR_QUERY, HI_WMI_ERROR_FETCH_PROPERTY, HI_WMI_ERROR_CONVERT_PROPERTY


WMI error codes

#define HI_WMI_OK   0
#define HI_WMI_ERROR_INIT_COM   -1
#define HI_WMI_ERROR_SECURITY   -2
#define HI_WMI_ERROR_CREATE_LOCATOR -3
#define HI_WMI_ERROR_CONNECT    -4
#define HI_WMI_ERROR_QUERY  -5
#define HI_WMI_ERROR_FETCH_PROPERTY -6
#define HI_WMI_ERROR_CONVERT_PROPERTY   -7

HI_WMI_ROOT_CIMV2


Root namespace

#define HI_WMI_ROOT_CIMV2   "ROOT\\CIMV2"

Functions

hi_wmi_connect


Connect to WMI and initialize handle

ARGUMENTS

RETURN VALUES
HI_WMI_OK if everything was fine or an error code

int hi_wmi_connect(hi_wmi_t* wmi, const char* ns) 

hi_wmi_disconnect


Disconnect to WMI and reset handle

ARGUMENTS

void hi_wmi_disconnect(hi_wmi_t* wmi) 

hi_wmi_query


Run a query

Data is returned as several rows in iterator iter. Initially
iterator contains no row, so you should call hi_wmi_next() to
fetch first row.

ARGUMENTS

RETURN VALUES
HI_WMI_OK if everything was fine or an error code

int hi_wmi_query(hi_wmi_t* wmi, hi_wmi_iter_t* iter, unsigned short* dialect, unsigned short* query) 

hi_wmi_next


Fetch next row from iterator. If query failed or no more rows are available,
returns B_FALSE. If next row was fetched, returns B_TRUE.

boolean_t hi_wmi_next(hi_wmi_iter_t* iter) 

hi_wmi_get_string_raw


Get a raw (UNICODE) string value from row

ARGUMENTS

RETURN VALUES
HI_WMI_OK if everything went fine, or HI_WMI_ERROR_FETCH_PROPERTY

int hi_wmi_get_string_raw(hi_wmi_iter_t* iter, unsigned short* name, char* str, size_t len) 

hi_wmi_get_string


Same as hi_wmi_get_string_raw(), but converts string to ASCII

int hi_wmi_get_string(hi_wmi_iter_t* iter, unsigned short* name, char* str, size_t len) 

hi_wmi_get_integer


Same as hi_wmi_get_string_raw(), but gets integer

int hi_wmi_get_integer(hi_wmi_iter_t* iter, unsigned short* name, int64_t* pi) 

hi_wmi_get_boolean


Same as hi_wmi_get_string_raw(), but gets boolean

int hi_wmi_get_boolean(hi_wmi_iter_t* iter, unsigned short* name, boolean_t* pb) 

Types

hi_wmi_t

typedef struct {
    IWbemLocator *loc;
    IWbemServices *svc;
} hi_wmi_t;

hi_wmi_iter_t

typedef struct {
    IEnumWbemClassObject* enumerator;
    IWbemClassObject *cls_obj;
} hi_wmi_iter_t;