Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i open a excel.exe during C# programing i want to be sure the user close excel file

i use this code but it dose not work what you think ?

Process[] prs = Process.GetProcesses();
                   foreach (Process pr in prs)
                   {
                       if (pr.ProcessName == "EXCEL.EXE *32")
                       {
                           pr.Kill();
                       }

                   }
Posted

A very general answer: instead of asking such question, run your code under debugger and see what process names are. You would solve your problem in a minute.

But the idea is not good: any process can accidentally have this name. You cannot guarantee that this is the process you are looking for; process names are not unique. And the whole idea of killing a process in a regular basis is really bad. You need to explain your ultimate goal. I'm almost sure we could suggest you some civilized approach to your problem. Killing is not a gentle thing and cannot give you good results.

—SA
 
Share this answer
 
Comments
farham_heidari 5-Dec-12 13:03pm    
what you suggest , i open an excel file my user make some change on it and save it , how can i be sure user close it ? because i open it with programing and calculate some thing there
C#
foreach (Process pr in prs)
                    {
                        MessageBox.Show(pr.ProcessName);
                        if (pr.ProcessName == "EXCEL")
                        {
                            pr.Kill();
                        }

                    }
 
Share this answer
 

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