dimanche 29 mars 2015

C++ : Disabling a device driver in Windows

Can anybody help me to tell why this code is not disabling the cdrom driver?It builds correctly.I debugged each line everything works perfectly. I have removed the error handling code and the cleanup code.



int main(int argc, char* argv[])
{

IWbemServices *pSvc = NULL;
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);

hres = CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL);
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator,LPVOID *)&pLoc);

hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&pSvc);

BSTR MethodName = SysAllocString(L"StopService");
BSTR ClassName = SysAllocString(L"Win32_SystemDriver");

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

VARIANT varCommand;

IWbemClassObject* pOutParams = NULL;
hres = pSvc->ExecMethod(L"Win32_SystemDriver.Name=\"cdrom\"", MethodName, 0,
NULL,NULL, &pOutParams, NULL);

VARIANT varReturnValue;
hres = pOutParams->Get(L"ReturnValue", 0, &varReturnValue, NULL, 0);
if (!FAILED(hres))
wcout << "ReturnValue " << varReturnValue.intVal << endl;
VariantClear(&varReturnValue);

// Clean up
SysFreeString(ClassName);
SysFreeString(MethodName);
return 0;
}


Please help..


Aucun commentaire:

Enregistrer un commentaire