Doubt

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

    #1

    Doubt

    Hi,

    Please clarifiy my doubt.


    In C# Without using Any API Calls, is there any way to get the ProcessID
    by giving the Handle of the Form.


    I go through System.Disagnos itcs, It's not accepting the Handle to kill the
    Process. It's accepting the Name only. or ProcessId. To Use the Methods
    I want to know the Process Id. Please let me know how to dothat?

    Regards,
    R.Baskar





  • Klaus H. Probst

    #2
    Re: Doubt

    If I'm understanding you correctly you have a window handle, right? Use
    GetWindowThread ProcessId through P/Invoke to get the ID, and then kill the
    process.


    --
    _______________ _____
    Klaus H. Probst, MVP
    http://www.vbbox.com/

    "Baskar RajaSekharan" <rbk@srasys.co. in> wrote in message
    news:uypgydWtDH A.1876@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Hi,
    >
    > Please clarifiy my doubt.
    >
    >
    > In C# Without using Any API Calls, is there any way to get the ProcessID
    > by giving the Handle of the Form.
    >
    >
    > I go through System.Disagnos itcs, It's not accepting the Handle to kill[/color]
    the[color=blue]
    > Process. It's accepting the Name only. or ProcessId. To Use the[/color]
    Methods[color=blue]
    > I want to know the Process Id. Please let me know how to dothat?
    >
    > Regards,
    > R.Baskar
    >
    >
    >
    >
    >[/color]


    Comment

    • Dmitriy Lapshin [C# / .NET MVP]

      #3
      Re: Doubt

      Hi,

      If you want to close an application by knowing its main window HWND (which
      is actually returned by Form.Handle), you could do the following:

      PostMessage(han dle, WM_QUIT, 0, 0)

      (assuming the PostMessage P/Invoke function and WM_QUIT constant are
      declared elsewhere)

      MSDN does not recommend sending this message and advises to use
      PostQuitMessage instead, but the latter cannot be used for another thread or
      process.

      You can also use WM_CLOSE, this could be even better (I used WM_QUIT since
      the application I wanted to close didn't have any windows).

      --
      Dmitriy Lapshin [C# / .NET MVP]
      X-Unity Test Studio

      Bring the power of unit testing to VS .NET IDE

      "Baskar RajaSekharan" <rbk@srasys.co. in> wrote in message
      news:uypgydWtDH A.1876@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hi,
      >
      > Please clarifiy my doubt.
      >
      >
      > In C# Without using Any API Calls, is there any way to get the ProcessID
      > by giving the Handle of the Form.
      >
      >
      > I go through System.Disagnos itcs, It's not accepting the Handle to kill[/color]
      the[color=blue]
      > Process. It's accepting the Name only. or ProcessId. To Use the[/color]
      Methods[color=blue]
      > I want to know the Process Id. Please let me know how to dothat?
      >
      > Regards,
      > R.Baskar
      >
      >
      >
      >
      >[/color]

      Comment

      Working...