Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project to run chkDsk through ExecMethod on a particular drive.
Too passing the drive name. But it's not running.

This is the final line:

hRes = m_pService->ExecMethod(ClassName, MethodName, 0, NULL, pClassInstance, &pOutParams, NULL);


Here ClassName is Win32_Volume & MethodName is Chkdsk.


& drive is passed through

VARIANT varParam7;
varParam7.vt = VT_BSTR;
varParam7.bstrVal = SysAllocString(L"E:");
hRes = pClass->Put(L"DriveLetter", 0,&varParam7, 0);

hRes is HRESULT which is giving S_OK for every line except the final one where we use ExecMethod.

Please solve the issue & too tell me how to get the status of this Chkdsk WMI query.
Posted

1 solution

You better DONT use the drive letter, but the complete UNC-path because the instance hasnt your druve mapping.
 
Share this answer
 
Comments
coolhimanshu.v 30-May-13 2:02am    
Thanks for the reply Karsten. Well, I too tried the UNC path as:
varParam7.bstrVal = SysAllocString(L"\\localhost\E$\\");

& then pass it as:

hRes = pClass->Put(L"DriveLetter", 0,&varParam7, 0);

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

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

then I set ChkDsk parameter as:
VARIANT var;
var.vt = VT_BOOL;
var.boolVal = VARIANT_FALSE;
hRes = pClassInstance->Put(L"FixErrors", 0, &var, CIM_BOOLEAN);
var.boolVal = VARIANT_TRUE;
hRes = pClassInstance->Put(L"VigorousIndexCheck", 0, &var, CIM_BOOLEAN);
hRes = pClassInstance->Put(L"SkipFolderCycle", 0, &var, CIM_BOOLEAN);
var.boolVal = VARIANT_FALSE;
hRes = pClassInstance->Put(L"ForceDismount", 0, &var, CIM_BOOLEAN);
hRes = pClassInstance->Put(L"RecoverBadSectors", 0, &var, CIM_BOOLEAN);
hRes = pClassInstance->Put(L"OkToRunAtBootUp", 0, &var, CIM_BOOLEAN);

& finally:
BSTR bstr;
hRes = pClassInstance->GetObjectText(0,&bstr);
wprintf(L"%s\n", bstr);
CComPtr<iwbemclassobject> pOut;
VARIANT vPath;
CIMTYPE Type;
long l;
pClass->Get(L"__Path", 0, &vPath, &Type, &l);

All HRESULTs are giving S_OK. But in final execution of chkdsk no S_OK :-(

HRESULT hr = m_pService->ExecMethod(vPath.bstrVal, L"Chkdsk", 0, 0, pClassInstance, &pOut, NULL);
KarstenK 30-May-13 2:05am    
You better use a suitable variable for the UNC-path because it ISNT a drive letter :-O

Havent you googled any working sample code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900