Discussion:
SetDNSDomain, Invalid Method Parameter error
(too old to reply)
_mg
2009-12-31 15:27:01 UTC
Permalink
I have the following code. SetDNSDomain is a per-adapter setting but I am
doing something wrong because I am getting an "Invalid Method Parameter"
error on ExecMethod. Everything works okay until the ExecMethod. I am not
sure that I pointing to the adapter vs. the class when I am making the call.
Is there an example of how to make a change to a unique device returned from
a query? Thanks.

====================================
int test3(void)
{
ULONG uReturn = 0;

BSTR MethodName = SysAllocString(L"SetDNSDomain");
BSTR ClassName = SysAllocString(L"Win32_NetWorkAdapterConfiguration");

// Query for network adapters
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * from Win32_NetworkAdapterConfiguration where Index= 1"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);

if (FAILED(hres))
{
cout << "Query for NIC Adapter failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 70;
}

while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

if(0 == uReturn) break;

IWbemClassObject* pClass = NULL;
IWbemClassObject* pInParams = NULL;
IWbemClassObject* pClassInstance = NULL;
IWbemClassObject* pOutParams = NULL;

BSTR suffix = SysAllocString(L"test.test1.com");
VARIANT arg1;
arg1.vt = VT_BSTR;
arg1.bstrVal = suffix;

hres = pSvc->GetObjectW(ClassName, 0, NULL, &pClass, NULL);
hres = pClass->GetMethod(MethodName, 0, &pInParams, NULL);
hres = pInParams->SpawnInstance(0, &pClassInstance);
hres = pClassInstance->Put(_T("DNSDomain"), 0, &arg1, 0);

VariantClear(&arg1);

hres = pSvc->ExecMethod(ClassName, MethodName, 0, NULL, pClassInstance,
&pOutParams, NULL);
if( hres != WBEM_S_NO_ERROR )
{
DisplayErrorText(hres);
pclsObj->Release();
return 71;
}

pclsObj->Release();
}

return 0;

}
_mg
2009-12-31 22:04:02 UTC
Permalink
Disregard, I found how to do this correctly...

I also ran into an issue because the network cable was disconnected. The
call returned an "IP not enabled" error. Seems that you should be able to
set this without a cable connected...
Post by _mg
I have the following code. SetDNSDomain is a per-adapter setting but I am
doing something wrong because I am getting an "Invalid Method Parameter"
error on ExecMethod. Everything works okay until the ExecMethod. I am not
sure that I pointing to the adapter vs. the class when I am making the call.
Is there an example of how to make a change to a unique device returned from
a query? Thanks.
====================================
int test3(void)
{
ULONG uReturn = 0;
BSTR MethodName = SysAllocString(L"SetDNSDomain");
BSTR ClassName = SysAllocString(L"Win32_NetWorkAdapterConfiguration");
// Query for network adapters
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * from Win32_NetworkAdapterConfiguration where Index= 1"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for NIC Adapter failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 70;
}
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if(0 == uReturn) break;
IWbemClassObject* pClass = NULL;
IWbemClassObject* pInParams = NULL;
IWbemClassObject* pClassInstance = NULL;
IWbemClassObject* pOutParams = NULL;
BSTR suffix = SysAllocString(L"test.test1.com");
VARIANT arg1;
arg1.vt = VT_BSTR;
arg1.bstrVal = suffix;
hres = pSvc->GetObjectW(ClassName, 0, NULL, &pClass, NULL);
hres = pClass->GetMethod(MethodName, 0, &pInParams, NULL);
hres = pInParams->SpawnInstance(0, &pClassInstance);
hres = pClassInstance->Put(_T("DNSDomain"), 0, &arg1, 0);
VariantClear(&arg1);
hres = pSvc->ExecMethod(ClassName, MethodName, 0, NULL, pClassInstance,
&pOutParams, NULL);
if( hres != WBEM_S_NO_ERROR )
{
DisplayErrorText(hres);
pclsObj->Release();
return 71;
}
pclsObj->Release();
}
return 0;
}
Loading...