locked
WMI fails on VISTA for EnableStatic RRS feed

  • Question

  •  

    I am porting some of our XP WMI code to Vista (which has SP1) and am having problems with several WMI (not all) calls.  All of the WMI calls are local.  I am starting with the first WMI call that doesn't work which is EnableStatic.  I am logged in as an admin and have disabled UAC.  The returncode I get with the following code is 80041003 which is access denied. I have taken out error checking in the following code to save space and at the end is where the only error in all of this occurs.  I have flat out run out of ideas and would really appreciate any suggesstions anyone can give.   Thanks. 

     

    IWbemServices * p_wbm_namespace;

    p_wbm_namespace = NULL;

    #define WBIM_SERVER_PATH L"root\\cimv2"

     

    i_wbm_stat =

    p_wbem_locator->ConnectServer(

    bstr_t(WBIM_SERVER_PATH),

    NULL, NULL, NULL, 0, NULL, NULL,

    &p_wbm_namespace);

    i_wbm_stat =

    CoSetProxyBlanket(p_wbm_namespace, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,

    NULL, RPC_C_AUTHN_LEVEL_CALL,

    RPC_C_IMP_LEVEL_IMPERSONATE, NULL,

    EOAC_NONE);

     

    IWbemClassObject * pClass;

    pClass = NULL;

    static char szbuf_className[512];

    sprintf(szbuf_className, "Win32_NetworkAdapterConfiguration" );

    CString str_path_class( szbuf_className );

    BSTR bstr_path_class;

    bstr_path_class = str_path_class.AllocSysString();

     

    i_wbm_stat = p_wbm_namespace->GetObject(bstr_path_class, 0, NULL,&pClass, NULL);

     

    HRESULT hr;

    int i_ret_code;

    //Build a string that points to the WBM intance for the adpater of interest

    static char szbuf_interfaceID[512];

    #define WBM_METHOD_ENABLE_STATIC "EnableStatic"

     

    --i_network_interfaceID was given a value in earlier code, it is basically an USB port that our device is connected to.

    sprintf(szbuf_interfaceID, "Win32_NetworkAdapterConfiguration.Index='%i'",i_network_interfaceID );

     

    CString str_interfaceID( szbuf_interfaceID );

    BSTR InstancePath;

    InstancePath = str_interfaceID.AllocSysString();

    CComBSTR MethodName = _T( WBM_METHOD_ENABLE_STATIC  );

    //Get a handle on the WBM method taht will set static IP Properties

    IWbemClassObject * pInClass = NULL;

    hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);

    IWbemClassObject * pInInst = NULL;

    hr = pInClass->SpawnInstance(0, &pInInst);

    IWbemClassObject * pOutInst = NULL;

    //Covert specified IP Address to WBM recognized BASIC String

    CString str_ip( "192.168.1.2" );

    BSTR st_bst_ip;

    st_bst_ip = str_ip.AllocSysString();

    //Covert specified IP Address to WBM recognized BASIC String

    CString str_subnet_mask( "255.255.255.0" );

    BSTR st_bst_snet_mask;

    st_bst_snet_mask = str_subnet_mask.AllocSysString();

    //Define index into (1) dimensional array that will define ip and snet vals

    long pi_list_vector_indexes[]={0};

    //Define (1) dimensional array that contains the IP Address

    SAFEARRAY *pst_safe_list_ip;

    pst_safe_list_ip = SafeArrayCreateVector(VT_BSTR,0,1);

    SafeArrayPutElement(pst_safe_list_ip,pi_list_vector_indexes, st_bst_ip );

    //Define (1) dimensional array that contains the Subnet mask

    SAFEARRAY *pst_safe_list_snet;

    pst_safe_list_snet = SafeArrayCreateVector(VT_BSTR,0,1);

    SafeArrayPutElement(pst_safe_list_snet,pi_list_vector_indexes,st_bst_snet_mask);

    //Build a VARIANT that contains the (1) dimensional array containing the

    // IP adddress

    //Then stuff the VARIANT into the IPAddress property spawned instance of

    // the EnableStatic WBM method that will be used to physically set the

    // IPAddress and subnet

    VARIANT arg1;

    arg1.vt = VT_ARRAY|VT_BSTR;

    arg1.parray = pst_safe_list_ip;

    BSTR st_artname_ip_addr = SysAllocString(L"IPAddress");

    hr = pInInst->Put(st_artname_ip_addr, 0, &arg1, 0);

    //Build a VARIANT that contains the (1) dimensional array containing the

    // subnet mask

    //Then stuff the VARIANT into the SubnetMask property spawned instance of

    // the EnableStatic WBM method that will be used to physically set the

    // IPAddress and subnet

    VARIANT arg2;

    arg2.vt = VT_ARRAY|VT_BSTR;;

    arg2.parray = pst_safe_list_snet;

    BSTR st_argname_snet_mask = SysAllocString(L"SubNetMask");

    hr = pInInst->Put(st_argname_snet_mask, 0, &arg2, 0);

    //Call WBM method to physically set the defined IPAddress and Subnet mask

    hr = p_wbm_namespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,

    &pOutInst, NULL);

    //Free resources used to set IP Address

    SysFreeString(st_artname_ip_addr);

    SysFreeString(st_argname_snet_mask);

    SysFreeString( st_bst_ip );

    SysFreeString( st_bst_snet_mask );

    SafeArrayDestroy(pst_safe_list_ip);

    SafeArrayDestroy(pst_safe_list_snet);

    VariantClear(&arg1);

    VariantClear(&arg2);

     

    //Now call the WBM service to get the return value of the invoked

    // EnableStatic method

    VARIANT ret_value;

    BSTR strReturnValue = SysAllocString(L"ReturnValue");

    hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);

    long ret = V_I4(&ret_value);

     

    -- The return code(ret_value) is 80041003

     

    SysFreeString(strReturnValue);

    VariantClear(&ret_value);

     

    Thursday, September 25, 2008 2:27 PM