Solved

Cannot end process

Posted on 2007-11-20
3
1,130 Views
Last Modified: 2013-12-17
I am trying to kill a process programmatically. I check to see if it is running and then try to kill it and I get the following exception and the process is not killed

base {System.SystemException} = {"Process must exit before requested information can be determined."}      

following is the code I am using to kill the process.

        private short KillProcess(string processName)
        {
            short count = 0;
            System.Diagnostics.Process[] excelInstances = System.Diagnostics.Process.GetProcesses();
            foreach (System.Diagnostics.Process excelInstance in excelInstances)
            {
                try
                {
                    if (excelInstance.ProcessName == "EXCEL")
                    {
                        excelInstance.Close();
                        excelInstance.Kill();
                    }
                    count += 1;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message.ToString());
                }
            }
            return count;
        }

thank you so much!!
0
Comment
Question by:pablo_munoz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
ID: 20321971
hi

Do you have the Google desktop installed? If it's present, it prevents Excel
from shutting down.

else shold your code defently kill excell

vbturbo
    void KillAllExcels() {
        System.Diagnostics.Process proc;
        foreach (proc in System.Diagnostics.Process.GetProcessesByName("EXCEL")) {
            proc.Kill();
        }
    }

Open in new window

0
 
LVL 3

Author Closing Comment

by:pablo_munoz
ID: 31410163
Thank you so Much!!
0
 
LVL 3

Author Comment

by:pablo_munoz
ID: 20322278
thank you so much!! seems like my code should of worked, was the exception being caused by the Close method of the instance?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question