Getting error parameters invalid to execute pSvc->ExecMethod()

Joined
Mar 22, 2011
Messages
1
Reaction score
0
I am trying to write application where I need to check the chkdsk. I used the WMI's Win32_LogicalDisk class.

I am trying to do operation on C: . I set the correct parameters whatever mentioned in MSDN.

Please see the following code.

BSTR MethodName = SysAllocString(L"Chkdsk");
BSTR ClassName = SysAllocString(L"Win32_LogicalDisk");
IWbemClassObject* pClass = NULL;




hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);

// Create the values for the in parameters
VARIANT varParam7;
varParam7.vt = VT_BSTR;
varParam7.bstrVal = SysAllocString(L"C:");
hres = pClass->Put(L"VolumeName", 0,&varParam7, 0);


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 varParam1;
varParam1.vt = VT_BOOL;
varParam1.boolVal = TRUE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"FixErrors", 0,&varParam1, 0);

// Create the values for the in parameters
VARIANT varParam2;
varParam2.vt = VT_BOOL;
varParam2.boolVal = TRUE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"VigorousIndexCheck", 0,&varParam2, 0);

// Create the values for the in parameters
VARIANT varParam3;
varParam3.vt = VT_BOOL;
varParam3.boolVal = TRUE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"SkipFolderCycle", 0,&varParam3, 0);


// Create the values for the in parameters
VARIANT varParam4;
varParam4.vt = VT_BOOL;
varParam4.boolVal = FALSE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"ForceDismount", 0,&varParam4, 0);

// Create the values for the in parameters
VARIANT varParam5;
varParam5.vt = VT_BOOL;
varParam5.boolVal = TRUE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"RecoverBadSectors", 0,&varParam5, 0);

// Create the values for the in parameters
VARIANT varParam6;
varParam6.vt = VT_BOOL;
varParam6.boolVal = FALSE;
// Store the value for the in parameters
hres = pClassInstance->Put(L"OKToRunAtBootUp", 0,&varParam6, 0);



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top