Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot end process

Posted on 2007-11-20
3
Medium Priority
?
1,141 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

730 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