Accessing Windows registry from samba wmic utility

Andrey Kondakov andreykondakov at
Wed Jul 25 12:00:17 MDT 2012

Hello All,

I am trying to add Windows registry support to wmic utility.
My code intends to access remote host and get some registry values or
enumerate keys.
Everything goes well until I try to fetch ReturnValue and actual query data
from *out* object.
Namely, ReturnValue should be 0 if the data returns but I get 6 instead
that supposedly addresses some HANDLE problem.

My flow is similar to Create process query which works perfect. The code
goes below.

I wonder if somebody can give me a hint how to get it working. Even some
relevant suggestion may help.

Thank you,


The code:

static WERROR WBEM_RemoteRegistryGetVal(struct IWbemServices *pWS, uint32_t
    struct IWbemClassObject *wco = NULL;
    struct IWbemClassObject *inc, *outc, *in;
    struct IWbemClassObject *out = NULL;
    WERROR result;
    union CIMVAR v, vkey, vsubkey, vvalue;
    TALLOC_CTX *ctx;

    ctx = talloc_new(0);

    printf("Getting StdRegProv object\n");

    result = IWbemServices_GetObject(pWS, ctx, "StdRegProv",

    if (wco == NULL){
        printf("Error no object\n");
    else {
        printf("Object is ok\n");

    printf("Result = [%s]\n", result);

    printf("Getting method EnumKey from StdRegProv object\n");

    result = IWbemClassObject_GetMethod(wco, ctx, "GetStringValue", 0,
&inc, &outc);

    result = IWbemClassObject_SpawnInstance(inc, ctx, 0, &in);

    vkey.v_string = "&H80000002";
    vsubkey.v_string = "Software\\JreMetrics";
    vvalue.v_string = "JreVersion";
    printf("Putting method parameters: Key -> HKLM, Sub key -> %s, Value ->
%s\n", vsubkey.v_string, vvalue.v_string);

    result = IWbemClassObject_Put(in, ctx, "hDefKey", 0, &vkey, 0);
    result = IWbemClassObject_Put(in, ctx, "sSubKeyName", 0, &vsubkey, 0);
    result = IWbemClassObject_Put(in, ctx, "sValueName", 0, &vvalue, 0);


    printf("Executing registry request\n");

    result = IWbemServices_ExecMethod(pWS, ctx, "StdRegProv",
"GetStringValue", 0, NULL, in, &out, NULL);

    result = WbemClassObject_Get(out->object_data, ctx, "ReturnValue", 0,
&v, 0, 0);
    *ret_code = v.v_uint32;

    return result;

More information about the samba-technical mailing list