8LWXpg / PowerToysRun-ProcessKiller

PowerToys Run Plugin to kill porcesses
MIT License
46 stars 3 forks source link

[Enhancement] Exclude only Shell process instead of all Explorer processes #5

Closed htcfreek closed 1 month ago

htcfreek commented 2 months ago

Currently all explorer processes are blocked for killing as system process.

Instead it is possible to only block the process if it hosts the Windows Shell.

In combination with the System setting "Run each explorer window in its own process" this allows killing Explorer.exe.

/// <summary>
        /// Gets a value indicating whether this is the shell process or not
        /// The shell process (like explorer.exe) hosts parts of the user interface (like taskbar, start menu, ...)
        /// </summary>
        internal bool IsShellProcess
        {
            get
            {
                IntPtr hShellWindow = NativeMethods.GetShellWindow();
                return GetProcessIDFromWindowHandle(hShellWindow) == ProcessID;
            }
        }

        /// <summary>
        /// Gets the process ID for the window handle
        /// </summary>
        /// <param name="hwnd">The handle to the window</param>
        /// <returns>The process ID</returns>
        internal static uint GetProcessIDFromWindowHandle(IntPtr hwnd)
        {
            _ = NativeMethods.GetWindowThreadProcessId(hwnd, out uint processId);
            return processId;
        }
8LWXpg commented 1 month ago

Are you willing to submit a PR for this? I'm asking because you’ve already provided a basic fix here.

htcfreek commented 1 month ago

Can do this. But the next weeks I don't have the time to work on it. So it will take some time to create the PR.

(The code snippets are copied from the PT Run Window Walker plugin code. The native methods used in the snippets are defined in Wox.Plugin.Common.Win32. You can add this class as using in your code.)