locked
how could i stop a running program in c#? RRS feed

  • Question

  • how could i stop a running program?, example i have an VFP application open and i want to update its executable using c#, so before i could overwrite the existing program to the updated one i have to close it if it is running, so when i open my updater program in c# the target executable if it is open should close automatically without going to its exit option.

    thank you very much for any help


    .madix_t
    Monday, July 13, 2009 4:58 AM

Answers

  • Hi,
      You can use Process class for your requirment. Suppose the exe which you want to stop is MyApp.exe, its procees name willbe MyApp. You can stop the process like following.

                Process[] proc = Process.GetProcessesByName("MyApp");
                foreach (Process prs in proc)
                {
                    prs.Kill();
                }

    -- Thanks Ajith R [Mark the best posts as Answers.]
    • Proposed as answer by Sharad Kumar Monday, July 13, 2009 7:43 AM
    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 5:20 AM
  • hi,

    You can get the process of your VFP application using Process.GetprocessByName("").
    Then you can kill it using Process.Kill().  refer http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

    Regards,
    Vinil


    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 5:22 AM
  • may be the appliation name is not correct..

    Process[] proc = Process.GetProcessesByName("MyApp");

    :: Learning .Net ::
    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 6:59 AM

All replies

  • Hi,
      You can use Process class for your requirment. Suppose the exe which you want to stop is MyApp.exe, its procees name willbe MyApp. You can stop the process like following.

                Process[] proc = Process.GetProcessesByName("MyApp");
                foreach (Process prs in proc)
                {
                    prs.Kill();
                }

    -- Thanks Ajith R [Mark the best posts as Answers.]
    • Proposed as answer by Sharad Kumar Monday, July 13, 2009 7:43 AM
    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 5:20 AM
  • hi,

    You can get the process of your VFP application using Process.GetprocessByName("").
    Then you can kill it using Process.Kill().  refer http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

    Regards,
    Vinil


    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 5:22 AM
  • hello Ajith R Nair

    i put your code in a click event of a button and why does the error message says "the name Process does not exist in current context" 

    thank you


    .madix_t
    Monday, July 13, 2009 6:27 AM
  • may be the appliation name is not correct..

    Process[] proc = Process.GetProcessesByName("MyApp");

    :: Learning .Net ::
    • Marked as answer by Madix_t Monday, July 13, 2009 8:06 AM
    Monday, July 13, 2009 6:59 AM
  • Add the reffernce system.diagnostic.process in your code

    Sharad Sharma Pursuit Technologies Bangalore
    Monday, July 13, 2009 7:44 AM
  • thanks to all of you for the help
    .madix_t
    Monday, July 13, 2009 8:06 AM