{"record":{"id":"af9a58b5847ae922","repo":"OdysseusYuan/LKY_OfficeTools","slug":"serv-name-binpath-serv-binpath","errorCode":null,"errorMessage":"修改服务 {serv_name} 的 binPath 信息为 {serv_binpath} 失败！","messagePattern":"修改服务 (.+?) 的 binPath 信息为 (.+?) 失败！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LKY_OfficeTools/Common/Com_ServiceOS.cs","lineNumber":395,"sourceCode":"                        {\n                            //已经创建服务，才进行修改\n                            string cmd_modify_binpath = $\"sc config \\\"{serv_name}\\\" binPath=\\\"{serv_binpath}\\\"\";\n                            var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_binpath);\n\n                            //非空判断，若返回值为空，则为假\n                            if (string.IsNullOrEmpty(modify_result))\n                            {\n                                throw new Exception($\"执行修改 {serv_name} binPath 参数时，返回值为空！\");\n                            }\n\n                            //判断是否修改 binPath 成功\n                            if (modify_result.Contains(\"成功\") || modify_result.ToLower().Contains(\"success\"))\n                            {\n                                return true;\n                            }\n                            else\n                            {\n                                throw new Exception($\"修改服务 {serv_name} 的 binPath 信息为 {serv_binpath} 失败！\");\n                            }\n                        }\n                        else\n                        {\n                            throw new Exception($\"尝试修改服务 {serv_name} 的 binPath 信息为 {serv_binpath}，但该服务未安装！\");\n                        }\n                    }\n                    catch (Exception Ex)\n                    {\n                        new Log(Ex.ToString());\n                        return false;\n                    }\n                }\n\n                internal static bool DisplayName(string serv_name, string serv_displayname)\n                {\n                    try\n                    {","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/OdysseusYuan/LKY_OfficeTools/blob/6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf/LKY_OfficeTools/Common/Com_ServiceOS.cs#L377-L413","documentation":"Thrown in Com_ServiceOS.Config.Modify.BinPath when the `sc config ... binPath=` stdout lacks the success markers 成功/success (Com_ServiceOS.cs:388-396). This is the genuine sc rejection path: sc ran and reported an error. Common sc failures are an invalid/missing executable path in binPath or access-denied. The throw is caught by BinPath's catch and it returns false (Com_ServiceOS.cs:403-407).","triggerScenarios":"Setting binPath to a non-existent file, a path the SCM cannot resolve (e.g. unquoted path with spaces, missing .exe), or calling without admin rights (sc config requires elevation).","commonSituations":"Migrating a service binary to a new install folder that does not yet exist; path with spaces passed unquoted into binPath; non-elevated reconfiguration tool.","solutions":["Run elevated; sc config requires administrator privileges.","Verify the new binPath file exists and quote paths containing spaces.","Check the bool return and the logged sc output to read the exact failure reason.","Use `sc qc <name>` afterwards to confirm the binPath was actually applied."],"exampleFix":"// before\nCom_ServiceOS.Config.Modify.BinPath(name, @\"C:\\Program Files\\App\\svc.exe\");\n\n// after\nstring bin = File.Exists(@\"C:\\Program Files\\App\\svc.exe\") ? @\"C:\\Program Files\\App\\svc.exe\" : null;\nif (bin == null) { /* fix path first */ return false; }\nCom_ServiceOS.Config.Modify.BinPath(name, bin);","handlingStrategy":"validation","validationCode":"string bin = File.Exists(serv_binpath) ? serv_binpath : null;\nif (bin == null) { /* fix path first */ return false; }\nbool ok = Com_ServiceOS.Config.Modify.BinPath(serv_name, bin);","typeGuard":"static bool ValidBinPath(string p) => !string.IsNullOrWhiteSpace(p) && File.Exists(p);","tryCatchPattern":null,"preventionTips":["Verify the new binPath file exists and quote paths containing spaces.","Run elevated; sc config requires administrator privileges.","Check the bool return of BinPath and the logged sc output.","Confirm with `sc qc <name>` after a successful change."],"tags":["windows-service","scm","service-config","binpath"],"backgroundTag":null,"analyzedSha":"6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf","analyzedAt":"2026-08-13T18:00:34.810Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}