k1tbyte/Wand-Enhancer · warning · Exception

Failed to kill WeMod

Error message

Failed to kill WeMod

What it means

Common.TryKillProcess loops up to 5 times (~250 ms apart, ~1.25 s total) calling Process.Kill on every instance of processName. If GetProcessesByName still returns instances after the loop, it throws. It is called from Enhancer.Patch() with _weModConfig.BrandName ('Wand' or 'WeMod').

Source

Thrown at WandEnhancer/Utils/Common.cs:39

                foreach (var process in processes)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch
                    {
                        // ignored
                    }
                }
                
                processes = Process.GetProcessesByName(processName);
                Thread.Sleep(250);
            }
            
            if (processes.Length > 0)
            {
                throw new Exception("Failed to kill WeMod");
            }
        }

        public static string GetCurrentDir()
        {
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;
            return Path.GetDirectoryName(assemblyLocation) ?? throw new InvalidOperationException();
        }
        
        public static string ComputeSha256Hash(string input)
        {
            using (var sha256 = System.Security.Cryptography.SHA256.Create())
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(input);
                var hashBytes = sha256.ComputeHash(bytes);
                return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
            }
        }

View on GitHub (pinned to 643c8f8b62)

Solutions

  1. Close Wand fully (tray -> Quit) before patching.
  2. Run the patcher as administrator so it can kill an elevated Wand process.
  3. Disable Wand auto-start / background relaunch during patching.
  4. Make the loop more robust: after Kill, call process.WaitForExit(timeout) instead of a fixed Thread.Sleep.
  5. Check Task Manager for lingering Wand/WeMod processes and end them manually.

Example fix

// before
foreach (var process in processes) {
    try { process.Kill(); } catch { /* ignored */ }
}
processes = Process.GetProcessesByName(processName);
Thread.Sleep(250);
// after
foreach (var process in processes) {
    try { process.Kill(); process.WaitForExit(2000); }
    catch { /* ignored */ }
    finally { process.Dispose(); }
}
Defensive patterns

Strategy: retry

Validate before calling

// Check liveness before patching and prompt the user instead of hard-failing
if (Process.GetProcessesByName(_weModConfig.BrandName).Length > 0) {
    if (!CanElevate())
        throw new InvalidOperationException("Wand is running elevated; relaunch the patcher as administrator.");
}

Type guard

static bool IsProcessKillable(string processName) {
    var p = Process.GetProcessesByName(processName).FirstOrDefault();
    if (p == null) return true;
    try { return p.HasExited || p.Responding; } catch { return false; } finally { p.Dispose(); }
}

Try / catch

try {
    enhancer.Patch(); // calls TryKillProcess internally
} catch (Exception ex) when (ex.Message == "Failed to kill WeMod") {
    // ask user to quit Wand from the tray, then retry; relaunch elevated if needed
}

Prevention

When it happens

Trigger: Enhancer.Patch() -> Common.TryKillProcess(BrandName) at Common.cs:11-41: after 5 iterations, Process.GetProcessesByName(processName).Length > 0. Each Kill() exception is swallowed, so a process that cannot be killed persists silently until the final check.

Common situations: Wand runs elevated but the patcher does not, so Kill() is access-denied and ignored; Wand's auto-updater/auto-start relaunches it within the retry window; the process is hung in a kernel call and ignores Kill; a watchdog respawns it.


AI-assisted analysis of k1tbyte/Wand-Enhancer@643c8f8b62 (2026-08-13). Data as JSON: /api/errors/456f20b3531de58a. Report an issue: GitHub.