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

ExecMethod fails with 0x80041002 WBEM_E_NOT_FOUND

478 views
Skip to first unread message

rmckee

unread,
Oct 28, 2008, 11:04:08 AM10/28/08
to
The ExecMethod fails with 0x80041002 WBEM_E_NOT_FOUND only in Vista.
The code works fine in XP.

// set up to call the SystemRestore::Restore method
BSTR MethodName = SysAllocString(L"Restore");
BSTR ClassName = SysAllocString(L"SystemRestore");

IWbemClassObject* pClass = NULL;
hres = service->GetObject(ClassName, 0, NULL, &pClass, NULL);

IWbemClassObject* pInParamsDefinition = NULL;
hres = pClass->GetMethod(MethodName, 0, &pInParamsDefinition, NULL);

IWbemClassObject* pClassInstance = NULL;
hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);

// Create the values for the in parameters
VARIANT varCommand;
varCommand.vt = VT_I4;
varCommand.iVal = nRestoreSequenceNumber_;

// Store the value for the in parameters
hres = pClassInstance->Put(L"SequenceNumber", 0, &varCommand, 0);

// Execute Method
IWbemClassObject* pOutParams = NULL;
hres = service->ExecMethod(ClassName, MethodName, 0, NULL, pClassInstance,
&pOutParams, NULL);


Any ideas what could be wrong?

Thanks

Seyfullah İZMİRLİ

unread,
Oct 29, 2008, 8:34:57 AM10/29/08
to
use this file
WMICodeCreator.exe
search with google

It can help you too much

Seyfullah İZMİRLİ
Software Specialist

"rmckee" <rmc...@discussions.microsoft.com>, haber iletisinde şunları
yazdı:15B38C7E-5928-4EE1...@microsoft.com...

rmckee

unread,
Oct 29, 2008, 9:01:02 AM10/29/08
to
Thanks for your help.
I have actually already tried it, but it only generates code for VBScript,
C#, and VB .NET.

I need code for C++.
Is there a similiar code generator for C++?

"Seyfullah ÝZMÝRLÝ" wrote:

> use this file
> WMICodeCreator.exe
> search with google
>
> It can help you too much
>

> Seyfullah ÝZMÝRLÝ
> Software Specialist
>
> "rmckee" <rmc...@discussions.microsoft.com>, haber iletisinde þunlarý
> yazdý:15B38C7E-5928-4EE1...@microsoft.com...

Gerry Hickman

unread,
Nov 9, 2008, 3:53:44 PM11/9/08
to
Hi,

What happens if you run this instead? (fix word wrap first)

Set RPSet = GetObject("winmgmts:root/default").InstancesOf ("SystemRestore")
for each RP in RPSet
wscript.Echo "Dir: RP" & RP.SequenceNumber & ", Name: " &
RP.Description & ", Type: ", RP.RestorePointType & ", Time: " &
RP.CreationTime
next

If that works, are you able to use the other methods such as "Enable",
"Disable" and "GetLastREstoreStatus"?


--
Gerry Hickman (London UK)

rmckee

unread,
Nov 11, 2008, 8:30:06 AM11/11/08
to
I'm not sure what the problem was, but I was able to get it to work with the
following code:

IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pOutInst = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;

BSTR path = SysAllocString(L"root\\default");
BSTR ClassPath = SysAllocString(L"SystemRestore");


BSTR MethodName = SysAllocString(L"Restore");

BSTR ArgName = SysAllocString(L"SequenceNumber");
BSTR Text;

// Initialize COM and connect to WMI.
HRESULT hr = CoInitialize(0);
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLocator);
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL,
NULL, &pNamespace);

// Get the class object for the method definition.

hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);

// Get the input-argument class object and create an instance.

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

// Set the property.
VARIANT var;
var.vt = VT_I4;
var.iVal = nRestoreSequenceNumber_;
hr = pInInst->Put(ArgName, 0, &var, 0);
VariantClear(&var);

// Call the method.
hr = pNamespace->ExecMethod(ClassPath, MethodName, 0, NULL,
pInInst, &pOutInst, NULL);

// Display the results. Note that the return value is in the
// property "ReturnValue" and the returned string is in the
// property "sOutArg".

hr = pOutInst->GetObjectText(0, &Text);
printf("\nThe object text is:\n%S", Text);

// Free up resources.
SysFreeString(path);
SysFreeString(ClassPath);
SysFreeString(MethodName);
SysFreeString(ArgName);
SysFreeString(Text);
pClass->Release();
pInInst->Release();
pInClass->Release();
pOutInst->Release();
pLocator->Release();
pNamespace->Release();
CoUninitialize();
printf("Terminating normally\n");

ermilin...@gmail.com

unread,
Apr 12, 2018, 10:16:49 AM4/12/18
to
I have a problem with ExecMethod for Calling CreateSnapshot, My `pOutParams.ResultingSnapshot` is returned as NULL even when the snapshot/checkpoint is created. Any clue about this?

Below is the text of pOutParams
instance of __PARAMETERS
{
Job = "\\\\WIN-ADU8U45M3SN\\root\\virtualization\\v2:Msvm_ConcreteJob.InstanceID=\"FF983E2C-2BC4-4FF1-822B-93922290B631\"";
ResultingSnapshot = NULL;
ReturnValue = 4096;
};
0 new messages