CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2004
    Posts
    166

    How to kill a process ?

    Hi,

    How can I kill a process in MFC?
    It's not a process that I have created, and all I know is the process name as it appears in "Windows task manager"...

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to kill a process ?

    Quote Originally Posted by yaniv_av
    How can I kill a process in MFC?
    It's not a process that I have created, and all I know is the process name as it appears in "Windows task manager"...
    Why would you want to do this... ?
    (as the process is not one of your creation...)

  3. #3
    Join Date
    May 2004
    Posts
    166

    Re: How to kill a process ?

    Quote Originally Posted by Siddhartha
    Why would you want to do this... ?
    (as the process is not one of your creation...)
    Well, I'll be more specific.
    I'm using some OCX from third-party. The OCX create the process.
    The problem is that even when I'm using the "Exit" function of the OCX - It won't kill the process it had created...
    So, if I'm using my app several times, I have several processes that are not kills from windows processes...
    So I want to create some app that go throght the active windows processes, and kill all the processes with the OCX process name...

  4. #4
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to kill a process ?

    Quote Originally Posted by yaniv_av
    Well, I'll be more specific.
    I'm using some OCX from third-party. The OCX create the process.
    The problem is that even when I'm using the "Exit" function of the OCX - It won't kill the process it had created...
    So, if I'm using my app several times, I have several processes that are not kills from windows processes...
    So I want to create some app that go throght the active windows processes, and kill all the processes with the OCX process name...
    The OCX is a COM Component.

    Perhaps, it terminates the processes it creates when the OCX itself is unloaded.

    As COM Components are reference counted, they are not simply unloaded when one client stops using them, but they get unloaded only when *all* clients stop using them.

    Hence, terminating that process (by force) is certainly going to cause unknown problems to the system, and to the clients of that OCX (other than yours.)

    In addition, a reference count bug can result in the OCX stay loaded for longer that its supposed to.

    I would recommend you to look up your usage of this Component.

    It is possible to detect and terminate processes, but in this case I would strongly discourage it as -

    • You are not aware of the impact of this action.
    • Terminating a process may leave many resources (like files opened, etc) in an unknown (read: unstable) state.

  5. #5
    Join Date
    May 2004
    Posts
    166

    Re: How to kill a process ?

    Quote Originally Posted by Siddhartha
    The OCX is a COM Component.

    Perhaps, it terminates the processes it creates when the OCX itself is unloaded.

    As COM Components are reference counted, they are not simply unloaded when one client stops using them, but they get unloaded only when *all* clients stop using them.

    Hence, terminating that process (by force) is certainly going to cause unknown problems to the system, and to the clients of that OCX (other than yours.)

    In addition, a reference count bug can result in the OCX stay loaded for longer that its supposed to.

    I would recommend you to look up your usage of this Component.

    It is possible to detect and terminate processes, but in this case I would strongly discourage it as -

    • You are not aware of the impact of this action.
    • Terminating a process may leave many resources (like files opened, etc) in an unknown (read: unstable) state.
    All of that is true, but what can I do ?
    I'm starting that OCX with "Init" function, and try to end it with "Exit" function (in the DTOR) - but the COM object is still up.
    And I 100% sure that my app is the only client for that OCX ...

  6. #6
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to kill a process ?

    Quote Originally Posted by yaniv_av
    All of that is true, but what can I do ?
    I'm starting that OCX with "Init" function, and try to end it with "Exit" function (in the DTOR) - but the COM object is still up.
    And I 100% sure that my app is the only client for that OCX ...
    Your Client is C++, right?

    I have not worked with OCX-s. But, a COM Component is to be instantiated by a call to CoCreateInstance.

    So, I dont understand this Init function!

    To answer your question, look up -

    You need to tweak the former, and use the latter.
    (But, attempt a workaround first...)

  7. #7
    Join Date
    May 2004
    Posts
    166

    Re: How to kill a process ?

    Quote Originally Posted by Siddhartha
    Your Client is C++, right?

    I have not worked with OCX-s. But, a COM Component is to be instantiated by a call to CoCreateInstance.

    So, I dont understand this Init function!

    To answer your question, look up -

    You need to tweak the former, and use the latter.
    (But, attempt a workaround first...)
    I'm using that OCX by put a static member function in my dialog (just like adding a button to a dialog). So I'm not using CoCreateInstance function.
    The "Init" function initiated some of the OCX properties...

    10x! - I'll look at those links.

  8. #8
    Join Date
    Aug 1999
    Posts
    586

    Re: How to kill a process ?

    Quote Originally Posted by yaniv_av
    I'm using that OCX by put a static member function in my dialog (just like adding a button to a dialog). So I'm not using CoCreateInstance function.
    The "Init" function initiated some of the OCX properties...

    10x! - I'll look at those links.
    Heed the advice of the others - don't shut something down unless you really know it's safe to do so (and understand the ramifications involved). If so then try this:

    http://support.microsoft.com/kb/q178893/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured