I have a code that checks if one specific process is running in the TaskManager with the code below. If not the function will start this process.
The code I use in a Form_Load event when the application starts. (Working code is below)

What I initially wonder is instead of a Form Application, I would only need some kind of file that should run this code. This means that you would double click a file that open/closes very fast while only running this code.

Is this possible to achieve somehow. I am not sure what possibilities there are to do this exactly?

      private void Form1_Load(object sender, EventArgs e)
            bool getInfo = IsProcessOpen("testApp");
            if (getInfo == false)
                //Start the application here
                String appLoc = "D:/Programs/testApp.exe";
                System.Diagnostics.Process startApplication = new System.Diagnostics.Process();
                    startApplication.StartInfo.FileName = appLoc;
                catch { }

        public bool IsProcessOpen(string name)
            //here we're going to get a list of all running processes on the computer
            foreach (System.Diagnostics.Process clsProcess in System.Diagnostics.Process.GetProcesses())
                String getName = clsProcess.ProcessName.ToString().ToLower();
                if (getName == name)
                    //if the process is found to be running then we return a true
                    return true;
            //otherwise we return a false
            return false;

Edited by Darth Vader

5 Years
Discussion Span
Last Post by ChrisHunter

You might have already solved this but you would probably benifit more from using a console app and just opening the other application depending on the result of your IsProcessOpen method.

It would be quicker because it doesn't have to initialise the UI componants of the Win Forms app and (like on the Win Form app) you can do Application.Exit where required.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.