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#
  4. Closing an open Task Manager window

Closing an open Task Manager window

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 3 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.
  • N Offline
    N Offline
    Nagendra Kamath K
    wrote on last edited by
    #1

    How to close an Task Manager window which is already open. Is there a way to get the process id of the Task Manager and end it? Anykind of help is highly appreciated. CHEERS I.T. D.U.D.E

    I H 2 Replies Last reply
    0
    • N Nagendra Kamath K

      How to close an Task Manager window which is already open. Is there a way to get the process id of the Task Manager and end it? Anykind of help is highly appreciated. CHEERS I.T. D.U.D.E

      I Offline
      I Offline
      ian mariano
      wrote on last edited by
      #2

      Hit escape ;P Use FindWindow to locate the window and send it a WM_KEYDOWN with VK_ESC.

      Ian Mariano - Bliki | Blog
      "We are all wave equations in the information matrix of the universe" - me

      1 Reply Last reply
      0
      • N Nagendra Kamath K

        How to close an Task Manager window which is already open. Is there a way to get the process id of the Task Manager and end it? Anykind of help is highly appreciated. CHEERS I.T. D.U.D.E

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Or just use something like this, which is all managed code:

        Process[] procs = Process.GetProcessesByName("taskmgr");
        if (procs != null)
        foreach (Process proc in procs)
        proc.Kill();

        Microsoft MVP, Visual C# My Articles

        I 1 Reply Last reply
        0
        • H Heath Stewart

          Or just use something like this, which is all managed code:

          Process[] procs = Process.GetProcessesByName("taskmgr");
          if (procs != null)
          foreach (Process proc in procs)
          proc.Kill();

          Microsoft MVP, Visual C# My Articles

          I Offline
          I Offline
          ian mariano
          wrote on last edited by
          #4

          I try to avoid Killing processes unless it's a last resort. To quote MSDN: "Data edited by the process or resources allocated to the process can be lost if you call Kill. Kill causes an abnormal process termination and should be used only when necessary." The task manager opens handles to the performance counters amongst other things. Just Killing it may not release them cleanly. Latter versions of Windows are better at handling reclaiming such resources, but I feel it's better to play nice.

          Ian Mariano - Bliki | Blog
          "We are all wave equations in the information matrix of the universe" - me

          H 1 Reply Last reply
          0
          • I ian mariano

            I try to avoid Killing processes unless it's a last resort. To quote MSDN: "Data edited by the process or resources allocated to the process can be lost if you call Kill. Kill causes an abnormal process termination and should be used only when necessary." The task manager opens handles to the performance counters amongst other things. Just Killing it may not release them cleanly. Latter versions of Windows are better at handling reclaiming such resources, but I feel it's better to play nice.

            Ian Mariano - Bliki | Blog
            "We are all wave equations in the information matrix of the universe" - me

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            There's always Process.CloseMainWindow. The idea is to avoid P/Invoking when possible since it can help lead to more portable code. It was an example and I would hope that for most code samples I post they just don't take them as-is - the ol' copy and paste. I try to teach people, not hand them the answers so they can continue their pursuit in ignorance. You may a good point, though.

            Microsoft MVP, Visual C# My Articles

            I 1 Reply Last reply
            0
            • H Heath Stewart

              There's always Process.CloseMainWindow. The idea is to avoid P/Invoking when possible since it can help lead to more portable code. It was an example and I would hope that for most code samples I post they just don't take them as-is - the ol' copy and paste. I try to teach people, not hand them the answers so they can continue their pursuit in ignorance. You may a good point, though.

              Microsoft MVP, Visual C# My Articles

              I Offline
              I Offline
              ian mariano
              wrote on last edited by
              #6

              Yes, and I believe that TaskMan.exe is a well-formed Windows app. Process.CloseMainWindow (MSDN) "in a well-formed application, closes child windows and revokes all running message loops for the application. The request to exit the process by calling CloseMainWindow does not force the application to quit...The behavior of CloseMainWindow is identical to that of a user closing an application's main window using the system menu. Therefore, the request to exit the process by closing the main window does not force the application to quit immediately."

              Ian Mariano - Bliki | Blog
              "We are all wave equations in the information matrix of the universe" - me

              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