Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to kill ongoing process and start another process. Then again kill the started application and relaunch the already killed process. Well on what i wrote, I am able to kill the ongoing process but not able to restart another application.
Do not know what i am missing or i might be coding it wrong way. Can someone help me?

What I have tried:

C#
public static void ManageApp(string app, bool Shutdown)
        {
            Process[] processes;
            string File = "NONE";

            if (app == "GUI")
            {
                app = "VGUI";
                File = "V.exe";
            }

            if (Shutdown)
            {
                #region " Kill Vertex GUI "
                try
                {
                    processes = Process.GetProcessesByName(app);
                    foreach (Process proc in processes)
                    {
                       
                        proc.Kill();
                        proc.WaitForExit(5000);
                    }

                }
                catch (System.NullReferenceException) {/* no instance running */}
                catch (Exception ex)
                {
                    Console.WriteLine(app + " shutdown exception: " + ex.Message);
                }
                #endregion " Kill Vertex GUI "
                #region "Launch Vertex GUI Mimic"
                try
                {
                    ProcessStartInfo proc1 = new ProcessStartInfo("Gui_Mimic.exe");
                    proc1.Arguments = @"C:\Program Files (x86)\Sp\Ver";
                    Process.Start(proc1);
                }
                catch (System.NullReferenceException) { }
                catch (Exception ex)
                {
                    Console.WriteLine(app + " shutdown exception: " + ex.Message);
                }
                #endregion "Launch Vertex GUI Mimic"
            }
            else{ ..... Some things .....    }
         }
Posted
Updated 14-Feb-23 0:36am
v3
Comments
0x01AA 4-Apr-22 8:25am    
Why not simply like this? Process.Start(@"C:\Windows\notepad.exe");
CHill60 4-Apr-22 8:31am    
Yep - worth posting as the solution. The OP has actually done the hard part :-)

1 solution

The simplest way to start a process is to pass the whole path. E.g. like:
C#
Process.Start(@"C:\Windows\notepad.exe");
 
Share this answer
 
Comments
DivyaHal 4-Apr-22 10:20am    
yeah actually i did try that somehow it did not work. I modified in other way and it worked. But now i am not able to kill that process to restart another process.
0x01AA 4-Apr-22 11:40am    
I think the problem is simple: To kill a process you need to use only the exe filename (without the whole path) while to start a process like shown above you should give the exe files complete path ;)
CHill60 4-Apr-22 13:25pm    
"somehow it did not work" - be specific - what happened?
" modified in other way" - be specific - what did you modify?
Remember, we cannot see your screen, access your hard drive nor read your brain. All we have to go on is the information you provide here. The more vague your explanations are, the longer it will take for anyone to provide a solution - if they even bother to try
0x01AA 4-Apr-22 13:38pm    
Thank you :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900