Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ExecMethod return failed status

80 views
Skip to first unread message

Jackie Lau

unread,
Feb 11, 2003, 4:53:58 PM2/11/03
to
Hi,
I'm trying to use WMI to set the IP and subnetMask
value. But I'm getting error in the ExecMethod. The error
description is "Message not found" when I use the error
look up tool in VC++. Please help...

Following is the code snippet:-


void CSystemData::setSystemData2()
{
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = NULL;
IWbemClassObject *pClass = NULL;
IWbemClassObject *pInputParamClass = NULL;
IWbemClassObject *pInputParamInstance = NULL;

BSTR InstancePath = SysAllocString
(L"Win32_NetworkAdapterConfiguration=1");

HRESULT hr;
BSTR Path = SysAllocString(L"root\\cimv2");
BSTR ClassPath = SysAllocString
(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IpAddress";

VARIANT var1;
CreateOneElementBstrArray(&var1, L"192.168.0.100");

LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
CreateOneElementBstrArray(&var2, L"255.255.255.0");

CoInitialize(0);

CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID *)&pLocator);

hr = pLocator->ConnectServer(Path, NULL, NULL,
NULL, 0, NULL, NULL, &pNamespace);
hr = pNamespace->GetObject(ClassPath, 0, NULL,
&pClass, NULL);
hr = pClass->GetMethod(MethodName, 0,
&pInputParamClass, NULL);
hr = pInputParamClass->SpawnInstance(0,
&pInputParamInstance);
hr = pInputParamInstance->Put(Arg1Name, 0, &var1,
0);
hr = pInputParamInstance->Put(Arg2Name, 0, &var2,
0);
hr = pNamespace->ExecMethod(InstancePath,
MethodName, 0, NULL, pInputParamInstance, NULL, NULL);

pInputParamInstance->Release();
pInputParamClass->Release();
pClass->Release();
pNamespace->Release();
pLocator->Release();
}

void CSystemData::CreateOneElementBstrArray(VARIANT* v,
LPCWSTR s)
{

SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}

Wade Hasbrouck [MSFT]

unread,
Feb 11, 2003, 5:24:07 PM2/11/03
to
What is the Error code? (the code that you put in the error look up tool)

When that tool returns "Message Not Found", it means that the tool was
unable to find a matching error code

You can find the WMI Error codes at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
wmi_error_constants.asp

--
Wade Hasbrouck
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Jackie Lau" <jacki...@philips.com> wrote in message
news:034c01c2d218$148d0730$a101...@phx.gbl...

Daniel Pravat [MSFT]

unread,
Feb 11, 2003, 5:53:25 PM2/11/03
to
WMI error codes are not recognized by ErrorLookup tool.
Please search MSDN for "WMI Error Constants" or use
IWbemStatusCodeText::GetErrorCodeText interface to get the description of
the error.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Jackie Lau" <jacki...@philips.com> wrote in message
news:034c01c2d218$148d0730$a101...@phx.gbl...

jacki...@philips.com

unread,
Feb 11, 2003, 6:07:35 PM2/11/03
to
The error code is 0x80041003 (WBEM_E_ACCESS_DENIED). How
do I get around this problem?

>.
>

Daniel Pravat [MSFT]

unread,
Feb 11, 2003, 7:27:38 PM2/11/03
to
Everybody loves to get around ACCESS_DENIED ;-)
Are you an administrator on your box? That is a reasonable
explanation for the message are you getting back.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


<jacki...@philips.com> wrote in message
news:08cb01c2d222$5d4577f0$2f01...@phx.gbl...

Jackie Lau

unread,
Feb 12, 2003, 4:38:40 PM2/12/03
to
Yes, I do have the administrator privelleges. I also added
my user name into the wbem control and grant all the
permission. But I'm still gettting the same
WBEM_E_ACCESS_DENIED error code. Is there any other test I
can do to rule out any programming error and make sure the
security is all setup correctly.

>.
>

Philip Nunn [MSFT]

unread,
Feb 12, 2003, 8:48:34 PM2/12/03
to
It looks like you may be missing the necessary call to CoInitializeSecurity.
WMI requires slightly higher settings for authentication and impersonation
than those provided to COM by the registry (which will be used if
CoInitializeSecurity is not called explicitly).

HRESULT hr = NULL;
hr = CoInitializeSecurity(
NULL, // security descriptor
-1, // use this simple setting
NULL, // use this simple setting
NULL, // reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // authentication level
RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
NULL, // use this simple setting
EOAC_NONE, // no special capabilities
0); // reserved


For more information see "Setting the Default Process Security Level using
C++" in the SDK.
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/setting_the_default_process_security_level_using_c_.asp?frame=true

--
-Philip

This posting is provided "As Is" with no warranties, and confers no rights.


"Jackie Lau" <jacki...@philips.com> wrote in message

news:017901c2d2df$1befde40$a101...@phx.gbl...

jacki...@philips.com

unread,
Feb 18, 2003, 2:26:16 PM2/18/03
to
Thanks!! The CoInitializeSecurity seems to fix the
problem. However, after the execution of my test program,
the IPAddress, gateway and subnetmask stay the same if I
do "ipconfig" at the command line or if I restart the
system. But if I check the registry using regedit, I can
see the changes. Any idea???

>.
>

0 new messages