{"record":{"id":"4c1669236824e652","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-kill-clash-verge-service-exe","errorCode":null,"errorMessage":"failed to kill clash-verge-service.exe","messagePattern":"failed to kill clash-verge-service\\.exe","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/init/mod.rs","lineNumber":254,"sourceCode":"        }\n    }\n    Ok(None)\n}\n\npub fn do_config_migration(old_app_dir: &PathBuf, app_dir: &PathBuf) -> anyhow::Result<()> {\n    let copy_option = CopyOptions::new();\n    let copy_option = copy_option.overwrite(true);\n    let copy_option = copy_option.content_only(true);\n    if let Err(e) = fs_extra::dir::move_dir(old_app_dir, app_dir, &copy_option) {\n        match e.kind {\n            #[cfg(windows)]\n            fs_extra::error::ErrorKind::PermissionDenied => {\n                // It seems that clash-verge-service is running, so kill it.\n                let status = RunasCommand::new(\"cmd\")\n                    .args(&[\"/C\", \"taskkill\", \"/IM\", \"clash-verge-service.exe\", \"/F\"])\n                    .status()?;\n                if !status.success() {\n                    anyhow::bail!(\"failed to kill clash-verge-service.exe\")\n                }\n                fs::rename(old_app_dir, app_dir)?;\n            }\n            _ => return Err(e.into()),\n        };\n    }\n    Ok(())\n}\n","sourceCodeStart":236,"sourceCodeEnd":263,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/init/mod.rs#L236-L263","documentation":"During config migration a PermissionDenied copy triggered an elevated taskkill of clash-verge-service.exe; the command ran but returned a non-zero status, so the migration bails — the service could not be force-killed.","triggerScenarios":"do_config_migration encountering fs_extra PermissionDenied while moving the old app dir, then RunasCommand taskkill /IM clash-verge-service.exe /F failing — service protected, UAC declined, or executable name changed.","commonSituations":"Upgrading versions while clash-verge-service is running and locking files; user cancels the UAC elevation prompt; service installed under a different name/path.","solutions":["Stop clash-verge-service properly (its uninstaller or 'sc stop' with admin rights) and rerun the migration.","Check whether the UAC prompt was declined; retry and accept elevation.","Verify the service process name matches 'clash-verge-service.exe'; adjust the taskkill target if renamed.","As a last resort, reboot (releases file locks) and rerun migration before starting the app."],"exampleFix":"// before\nlet status = RunasCommand::new(\"cmd\")\n    .args(&[\"/C\", \"taskkill\", \"/IM\", \"clash-verge-service.exe\", \"/F\"])\n    .status()?;\nif !status.success() {\n    anyhow::bail!(\"failed to kill clash-verge-service.exe\")\n}\n// after\nlet status = RunasCommand::new(\"cmd\")\n    .args(&[\"/C\", \"taskkill\", \"/IM\", \"clash-verge-service.exe\", \"/F\"])\n    .status()?;\nif !status.success() {\n    anyhow::bail!(\"failed to kill clash-verge-service.exe; stop the service manually (sc stop clash_verge_service) and retry\");\n}","handlingStrategy":"try-catch","validationCode":"// detect the locking service before attempting migration\nlet locked = std::process::Command::new(\"tasklist\")\n    .args(&[\"/FI\", \"IMAGENAME eq clash-verge-service.exe\"])\n    .output()\n    .map(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains(\"clash-verge-service\"))\n    .unwrap_or(false);\nif locked { println!(\"stop clash-verge-service before migrating\"); }","typeGuard":null,"tryCatchPattern":"match do_config_migration().await {\n    Err(e) if e.to_string().contains(\"failed to kill clash-verge-service\") => {\n        eprintln!(\"stop the service manually (admin): taskkill /IM clash-verge-service.exe /F, then retry\");\n    }\n    other => other,\n}","preventionTips":["Shut down clash-verge-service via the app before upgrading","Accept the UAC elevation prompt when shown","Reboot if file locks persist, then rerun migration"],"tags":["windows","migration","service","permission","elevation"],"backgroundTag":"permission-denied","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}