heiswayi nrird Just another Software Engineer who loves coffee ...

Mini App Killer

Mini App Killer is a mini lightweight application I created in .NET C# that will sit in your system tray for easy access to simply kill or end task any running application. Other than terminating the running application, you also can open the running application directory (Open file location) or show application File Properties.

Download MiniAppKillerV1.zip · 55.2 KB

By default, Mini App Killer program will list all running applications or processes that contain MainWindowTitle property from the WMI query.

C# code snippet:

var wmiQueryString = "SELECT ProcessId, ExecutablePath FROM Win32_Process";
using(var searcher = new ManagementObjectSearcher(wmiQueryString))
using(var results = searcher.Get()) {
    var query = from p in Process.GetProcesses()
    join mo in results.Cast<ManagementObject>()
    on p.Id equals(int)(uint) mo["ProcessId"]
    select new {
        Process = p,
        Path = (string)mo["ExecutablePath"],
    };

    if (query.Count() > 0) {
        foreach(var item in query) {
            if (!string.IsNullOrEmpty(item.Process.MainWindowTitle)) {
                // List all running application here...
            }
        }
    }
}

Screenshot:

Listing all running applications

To kill the running application

Here are the C# code I use to kill the application, open file location or show application File Properties dialog from the WMI query results:

// To kill the running application based on Process Id.
Process.GetProcessById(item.Process.Id).Kill();

// To open the running application directory and select the executable file.
Process.Start("explorer.exe", "/select, \"" + item.Path + "\"");

// To show the application File Properties
ShowFileProperties(item.Path);

#region Unmanaged code for ShowFileProperties(path)
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHELLEXECUTEINFO {
    public int cbSize;
    public uint fMask;
    public IntPtr hwnd;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpVerb;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpFile;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpParameters;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpDirectory;
    public int nShow;
    public IntPtr hInstApp;
    public IntPtr lpIDList;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string lpClass;
    public IntPtr hkeyClass;
    public uint dwHotKey;
    public IntPtr hIcon;
    public IntPtr hProcess;
}

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
public static bool ShowFileProperties(string Filename) {
    SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
    info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
    info.lpVerb = "properties";
    info.lpFile = Filename;
    info.nShow = SW_SHOW;
    info.fMask = SEE_MASK_INVOKEIDLIST;
    return ShellExecuteEx(ref info);
}
#endregion

Customize filter…

To filter for specific process name (application executable name without extension), there is a function called “Customize filter…” on the Mini App Killer. When you click it, a window for adding process name will be shown as below:

Customize filter...

Mini App Killer program will list all running applications that contain the process name as defined in the “Customize filter…” window when “Enable filtered by process name…” checkbox is checked.

Filtered by process name

This is how WMI query code looked like for filtering the target process names:

string[] _targetProcessNames = ... // Array of process names to filter..

var query = from p in Process.GetProcesses()
            where _targetProcessNames.Any(n => n.Equals(p.ProcessName, StringComparison.InvariantCultureIgnoreCase))
            join mo in results.Cast<ManagementObject>()
            on p.Id equals(int)(uint) mo["ProcessId"]
            select new {
              Process = p,
              Path = (string)mo["ExecutablePath"],
            };

App settings

All filtered process names will be saved to a text file named as filters.txt, which is easy for user to read or modify directly from the file.

filters.txt

# This file is auto-generated by Mini App Killer
chrome
ccleaner64

I use .INI file for saving the Mini App Killer application settings as it’s simple and easy. The source code for .INI file helper class is available on my gist here.