Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WMI Terminate Win32_Process

WMI Terminate Win32_Process

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasejson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Farry
    wrote on last edited by
    #1

    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);

    N 1 Reply Last reply
    0
    • P Paul Farry

      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);

      N Offline
      N Offline
      nilaysoft
      wrote on last edited by
      #2

      Sorry, these two messages have been merged because of unknow reason. I don't know why... My Programming Page

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups