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. COM
  4. Killing Process Using WMI

Killing Process Using WMI

Scheduled Pinned Locked Moved COM
helpannouncement
1 Posts 1 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.
  • A Offline
    A Offline
    abhiramsss
    wrote on last edited by
    #1

    hi I am working killing a process using WMI iam using the following code . HRESULT hres; BSTR ClassName = SysAllocString(L"Win32_Process"); /* YOU NEED TO CHANGE THE NUMBER VALUE OF THE HANDLE (PROCESS ID) TO THE CORRECT VALUE OF THE PROCESS YOU ARE TRYING TO TERMINATE (this provides a path to the class instance you are tying to terminate). */ BSTR ClassNameInstance = SysAllocString( L"Win32_Process.Handle=\"\1418\""); _bstr_t MethodName = (L"Terminate"); BSTR ParameterName = SysAllocString(L"Reason"); IWbemClassObject* pClass = NULL; hres = m_pIWbemService->GetObject(ClassName, 0, NULL, &pClass, NULL); IWbemClassObject* pInParamsDefinition = NULL; IWbemClassObject* pOutMethod = NULL; hres = pClass->GetMethod(MethodName, 0, &pInParamsDefinition, &pOutMethod); if (FAILED(hres)) { cout << "Could not get the method. Error code = 0x" << hex << hres << endl; } IWbemClassObject* pClassInstance = NULL; hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance); // Create the values for the in parameters VARIANT pcVal; VariantInit(&pcVal); V_VT(&pcVal) = VT_I4; // Store the value for the in parameters hres = pClassInstance->Put(L"Reason", 0, &pcVal, 0); // Execute Method hres = m_pIWbemService->ExecMethod(ClassNameInstance, MethodName, 0, NULL, pClassInstance, NULL, NULL); if (FAILED(hres)) { cout << "Could not execute method. Error code = 0x" << hex << hres << endl; VariantClear(&pcVal); SysFreeString(ClassName); SysFreeString(MethodName); pClass->Release(); pInParamsDefinition->Release(); m_pIWbemService->Release(); //pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } it is working fine ,but here iam gicing the Process ID which has to be terminated like 1418. Instead of ProcessID i want to use process Name like CAlc.exe or notepad.exe but when IAm tring to change the code with the process name like SysAllocString( L"Win32_Process.Name=\"\notepad.exe\""); notepad is not terminating . can you please help me to solve it. Thanks in Advance

    abhi

    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