WMI Terminate Win32_Process
-
Has anyone got a code snippet for Terminating a process through using the C++ API into the WMI libraries. I've been fumbling around, and cannot get it to ExecMethod. I've successfully created a process, and been able to query processes for a specific processid, but now I want to terminate it. I can't find any examples in VC++. This is kinda where I'm at. If someone could please tell me what I'm doing wrong that'd be great. m_pServer is connected, m_ProcessID is a valid ProcessID. There are not a lot of examples of using WMI in VC++. IWbemClassObject * pClass = NULL; IWbemClassObject * pInArg = NULL; IWbemClassObject * pInClass = NULL; IWbemClassObject * pInMethod = NULL; IWbemClassObject * pOutMethod = NULL; BSTR ClassName = SysAllocString(L"Win32_Process"); BSTR MethodName = SysAllocString(L"Terminate"); BSTR ParameterName = SysAllocString(L"ProcessId"); LPCWSTR method = OLE2CW(MethodName); VARIANT pcVal; VariantInit(&pcVal); V_I4(&pcVal) = m_ProcessID; V_VT(&pcVal) = VT_I4; hr = m_pServer->GetObject(ClassName,0, NULL, &pClass, NULL); hr = pClass->GetMethod(method, 0, &pInMethod, &pOutMethod); hr = pInMethod->SpawnInstance(0, &pInArg); hr = pInArg->Put(OLE2CW(ParameterName) , 0, &pcVal, 0); hr = m_pServer->ExecMethod(ClassName, MethodName, 0, NULL, pInArg, NULL, NULL);
-
Has anyone got a code snippet for Terminating a process through using the C++ API into the WMI libraries. I've been fumbling around, and cannot get it to ExecMethod. I've successfully created a process, and been able to query processes for a specific processid, but now I want to terminate it. I can't find any examples in VC++. This is kinda where I'm at. If someone could please tell me what I'm doing wrong that'd be great. m_pServer is connected, m_ProcessID is a valid ProcessID. There are not a lot of examples of using WMI in VC++. IWbemClassObject * pClass = NULL; IWbemClassObject * pInArg = NULL; IWbemClassObject * pInClass = NULL; IWbemClassObject * pInMethod = NULL; IWbemClassObject * pOutMethod = NULL; BSTR ClassName = SysAllocString(L"Win32_Process"); BSTR MethodName = SysAllocString(L"Terminate"); BSTR ParameterName = SysAllocString(L"ProcessId"); LPCWSTR method = OLE2CW(MethodName); VARIANT pcVal; VariantInit(&pcVal); V_I4(&pcVal) = m_ProcessID; V_VT(&pcVal) = VT_I4; hr = m_pServer->GetObject(ClassName,0, NULL, &pClass, NULL); hr = pClass->GetMethod(method, 0, &pInMethod, &pOutMethod); hr = pInMethod->SpawnInstance(0, &pInArg); hr = pInArg->Put(OLE2CW(ParameterName) , 0, &pcVal, 0); hr = m_pServer->ExecMethod(ClassName, MethodName, 0, NULL, pInArg, NULL, NULL);
Sorry, these two messages have been merged because of unknow reason. I don't know why... My Programming Page