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. Process termination

Process termination

Scheduled Pinned Locked Moved C#
tutorial
6 Posts 5 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi , two notepad are running one is saved as first.txt other is saved as second.txt how to kill only one process first.txt I am using the following code which is closing all the notepad

    foreach (Process pre in Process.GetProcesses())
    {

            if (pre.ProcessName.StartsWith("notepad"))
                {
              
    
                    pre.Kill();
    
                      
                }
        }
    

    Regards, Amit Patel

    E D P 3 Replies Last reply
    0
    • L Lost User

      Hi , two notepad are running one is saved as first.txt other is saved as second.txt how to kill only one process first.txt I am using the following code which is closing all the notepad

      foreach (Process pre in Process.GetProcesses())
      {

              if (pre.ProcessName.StartsWith("notepad"))
                  {
                
      
                      pre.Kill();
      
                        
                  }
          }
      

      Regards, Amit Patel

      E Offline
      E Offline
      Elayaraja Sambasivam
      wrote on last edited by
      #2

      Find the main window of the process first, next get the caption of window, check your condition, if it's satisfy then kill that process...

      1 Reply Last reply
      0
      • L Lost User

        Hi , two notepad are running one is saved as first.txt other is saved as second.txt how to kill only one process first.txt I am using the following code which is closing all the notepad

        foreach (Process pre in Process.GetProcesses())
        {

                if (pre.ProcessName.StartsWith("notepad"))
                    {
                  
        
                        pre.Kill();
        
                          
                    }
            }
        

        Regards, Amit Patel

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        You can do that by checking Process.MainWindowTitle property.

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        1 Reply Last reply
        0
        • L Lost User

          Hi , two notepad are running one is saved as first.txt other is saved as second.txt how to kill only one process first.txt I am using the following code which is closing all the notepad

          foreach (Process pre in Process.GetProcesses())
          {

                  if (pre.ProcessName.StartsWith("notepad"))
                      {
                    
          
                          pre.Kill();
          
                            
                      }
              }
          

          Regards, Amit Patel

          P Offline
          P Offline
          prasadbuddhika
          wrote on last edited by
          #4

          what about this

          Process[] pro = Process.GetProcessesByName("Notepad");
          pro[0].Kill();

          L 1 Reply Last reply
          0
          • P prasadbuddhika

            what about this

            Process[] pro = Process.GetProcessesByName("Notepad");
            pro[0].Kill();

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            this is way i m not getting the saved file name

            C 1 Reply Last reply
            0
            • L Lost User

              this is way i m not getting the saved file name

              C Offline
              C Offline
              Calla
              wrote on last edited by
              #6

              I'm not sure what you mean with this.. But if you're having trouble closing the correct notepad process, try keeping the Process's Id in memory (knowing the Id of the first and the second notepad process). Then you are sure to close the right one..

              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