How to kill a process of a calling app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jake

    How to kill a process of a calling app

    Hello,

    I have an application that calls another application. Depending on what
    the user selects from application 2 I would like to kill application 1. How
    can I accomplish this? Thanks in advance.

    Jake


  • Herfried K. Wagner [MVP]

    #2
    Re: How to kill a process of a calling app

    "jake" <rondican@hotma il.com> schrieb:[color=blue]
    >I have an application that calls another application. Depending on what the
    >user selects from application 2 I would like to kill application 1. How can
    >I accomplish this?[/color]

    If you want to be notified about user interaction in the other application
    (for example, clicking buttons), you will have to utilize a Win32 hook,
    typically implemented in a standard Win32 DLL implemented in VC++ or Delphi.

    For starting and closing a process, take a look at this code:

    \\\
    Imports System.Diagnost ics
    ..
    ..
    ..
    Dim p As Process = Process.Start(. ..)
    ....
    If...Then
    p.CloseMainWind ow()
    End If
    ....
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Crouchie1998

      #3
      RE: How to kill a process of a calling app

      The creation of the process is not close application one like the user wanted

      Yes, the user can launch the second application using your code, but you
      don't go as far as closing the first one.

      Obviously, a way of going about it is to pass the Handle of the first
      application to the second & using DestroyWindow to kill it off.

      Another way to go about it is to get the process name of application one
      from application two & then killing application one from that. So, all you
      have to do is to GetProcessByNam e etc.

      "jake" wrote:
      [color=blue]
      > Hello,
      >
      > I have an application that calls another application. Depending on what
      > the user selects from application 2 I would like to kill application 1. How
      > can I accomplish this? Thanks in advance.
      >
      > Jake
      >
      >
      >[/color]

      Comment

      • jake

        #4
        Re: How to kill a process of a calling app

        Crouchie1998,

        Do you have a sample on how to do this or a link to get me started? I
        would appreciate it. Thanks.

        Jake
        "Crouchie19 98" <Crouchie1998@d iscussions.micr osoft.com> wrote in message
        news:3C8D3353-392A-44F9-9D44-E1D9FF994B19@mi crosoft.com...[color=blue]
        > The creation of the process is not close application one like the user
        > wanted
        >
        > Yes, the user can launch the second application using your code, but you
        > don't go as far as closing the first one.
        >
        > Obviously, a way of going about it is to pass the Handle of the first
        > application to the second & using DestroyWindow to kill it off.
        >
        > Another way to go about it is to get the process name of application one
        > from application two & then killing application one from that. So, all you
        > have to do is to GetProcessByNam e etc.
        >
        > "jake" wrote:
        >[color=green]
        >> Hello,
        >>
        >> I have an application that calls another application. Depending on
        >> what
        >> the user selects from application 2 I would like to kill application 1.
        >> How
        >> can I accomplish this? Thanks in advance.
        >>
        >> Jake
        >>
        >>
        >>[/color][/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: How to kill a process of a calling app

          "Crouchie19 98" <Crouchie1998@d iscussions.micr osoft.com> schrieb:[color=blue]
          > Obviously, a way of going about it is to pass the Handle of the first
          > application to the second & using DestroyWindow to kill it off.[/color]

          MSDN:

          ---
          A thread cannot use 'DestroyWindow' to destroy a window created by a
          different thread.
          ---

          Instead, you can send a 'WM_CLOSE' to the window, the window will call
          'DestroyWindow' itself.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          Working...