Solved

Cannot end process

Posted on 2007-11-20
3
1,129 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

696 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