Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel zombie process on debugging stop from Visual Studio

During app debugging (Visual Studio 2012, C#, Excel COM Interop) I usually stop the app from Visual Studio (exception, or the logic is broken). This leaves started from the app Excel instance to hang in the memory. Yes, I can kill it from the Task Manager, but it is pretty annoying. Is there any way to "customize" dependency between Excel and my app process?

like image 393
Denis Gladkiy Avatar asked Feb 02 '26 04:02

Denis Gladkiy


1 Answers

I have a Powershell function defined in my profile (C:\Users\{userName}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1)

function Kill-Excel {
    $excelInstances = @(Get-Process | Where { $_.Name -Eq "Excel" }).Count
    if ($excelInstances -Eq 0) {
        "Excel not running"
    }
    else {
        if ($excelInstances -Eq 1) {
            "Killing 1 instance of Excel"
        }
        else {
            "Killing $excelInstances instances of Excel"
        }
        Get-Process | Where { $_.Name -Eq "Excel" } | Kill
    }
}

Then I just type Kill-Excel in a Powershell prompt which kills all Excel instances, hidden and visible, on my machine.

Note that this will take down any Excel instances you have open without prompting to save.

like image 131
Patrick McDonald Avatar answered Feb 04 '26 17:02

Patrick McDonald