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 in C# (Open exe)

Process in C# (Open exe)

Scheduled Pinned Locked Moved C#
csharp
8 Posts 4 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.
  • S Offline
    S Offline
    ShafiqA
    wrote on last edited by
    #1

    Hi Guy, I need to open exe through C#. I am able to open exe by writing code System.Diagnostics.Process.Start("C:\Program Files\abc\xyz.exe"); but now I need to check if it is already open then no need to run this code because it will reopen. basically need to check whether its open or not, open only if not open.... Thanks&Regards Shafiq...

    M L C 3 Replies Last reply
    0
    • S ShafiqA

      Hi Guy, I need to open exe through C#. I am able to open exe by writing code System.Diagnostics.Process.Start("C:\Program Files\abc\xyz.exe"); but now I need to check if it is already open then no need to run this code because it will reopen. basically need to check whether its open or not, open only if not open.... Thanks&Regards Shafiq...

      M Offline
      M Offline
      monstale
      wrote on last edited by
      #2

      Hi, check this[^] Hope it helps :-) Bye

      1 Reply Last reply
      0
      • S ShafiqA

        Hi Guy, I need to open exe through C#. I am able to open exe by writing code System.Diagnostics.Process.Start("C:\Program Files\abc\xyz.exe"); but now I need to check if it is already open then no need to run this code because it will reopen. basically need to check whether its open or not, open only if not open.... Thanks&Regards Shafiq...

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

        Try following code...

        //Namespaces we need to use
        using System.Diagnostics;

        public bool IsProcessOpen(string name)
        {
        //here we're going to get a list of all running processes on
        //the computer
        foreach (Process clsProcess in Process.GetProcesses()) {
        //now we're going to see if any of the running processes
        //match the currently running processes. Be sure to not
        //add the .exe to the name you provide, i.e: NOTEPAD,
        //not NOTEPAD.EXE or false is always returned even if
        //notepad is running.
        //Remember, if you have the process running more than once,
        //say IE open 4 times the loop thr way it is now will close all 4,
        //if you want it to just close the first one it finds
        //then add a return; after the Kill
        if (clsProcess.ProcessName.Contains(name))
        {
        //if the process is found to be running then we
        //return a true
        return true;
        }
        }
        //otherwise we return a false
        return false;
        }

        Jinal Desai - LIVE Experience is mother of sage....

        S 1 Reply Last reply
        0
        • L Lost User

          Try following code...

          //Namespaces we need to use
          using System.Diagnostics;

          public bool IsProcessOpen(string name)
          {
          //here we're going to get a list of all running processes on
          //the computer
          foreach (Process clsProcess in Process.GetProcesses()) {
          //now we're going to see if any of the running processes
          //match the currently running processes. Be sure to not
          //add the .exe to the name you provide, i.e: NOTEPAD,
          //not NOTEPAD.EXE or false is always returned even if
          //notepad is running.
          //Remember, if you have the process running more than once,
          //say IE open 4 times the loop thr way it is now will close all 4,
          //if you want it to just close the first one it finds
          //then add a return; after the Kill
          if (clsProcess.ProcessName.Contains(name))
          {
          //if the process is found to be running then we
          //return a true
          return true;
          }
          }
          //otherwise we return a false
          return false;
          }

          Jinal Desai - LIVE Experience is mother of sage....

          S Offline
          S Offline
          ShafiqA
          wrote on last edited by
          #4

          Hey Jinal Desai Where i need to give the path of my exe file which i need to open and can check that particular process running or not instead of checking all running process on the computer.

          L 1 Reply Last reply
          0
          • S ShafiqA

            Hey Jinal Desai Where i need to give the path of my exe file which i need to open and can check that particular process running or not instead of checking all running process on the computer.

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

            You did not want to give path of your exe file, just give the name of it.

            Jinal Desai - LIVE Experience is mother of sage....

            S 1 Reply Last reply
            0
            • L Lost User

              You did not want to give path of your exe file, just give the name of it.

              Jinal Desai - LIVE Experience is mother of sage....

              S Offline
              S Offline
              ShafiqA
              wrote on last edited by
              #6

              na.. Its not working for me.

              L 1 Reply Last reply
              0
              • S ShafiqA

                na.. Its not working for me.

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

                The process name is case sensitive in some case, so try with case sensitive and check in "Window Task Manager" whether your exe is running or not. If running then give the name as shown in it. HTH

                Jinal Desai - LIVE Experience is mother of sage....

                1 Reply Last reply
                0
                • S ShafiqA

                  Hi Guy, I need to open exe through C#. I am able to open exe by writing code System.Diagnostics.Process.Start("C:\Program Files\abc\xyz.exe"); but now I need to check if it is already open then no need to run this code because it will reopen. basically need to check whether its open or not, open only if not open.... Thanks&Regards Shafiq...

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

                  Have a look at this snippet. Just change "notepad" (which I used here) to your process name (xyz?).

                  List<Process> pList = new List(Process.GetProcesses());
                  Process pSearch = pList.Find( delegate(Process p)
                  { return p.ProcessName.ToLower() == "notepad";
                  } );

                  If pSerach is null Notepad is not running, otherwise you retrieve the Process object for Notepad. [EDIT] Nah, just look at Process.GetProcessesByName(string). No need to make it more complicated than that I suppose.. :)

                  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