{"record":{"id":"7eb9319a73848ee9","repo":"OdysseusYuan/LKY_OfficeTools","slug":"serv-name-binpath-serv-binpath-7eb931","errorCode":null,"errorMessage":"尝试修改服务 {serv_name} 的 binPath 信息为 {serv_binpath}，但该服务未安装！","messagePattern":"尝试修改服务 (.+?) 的 binPath 信息为 (.+?)，但该服务未安装！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"LKY_OfficeTools/Common/Com_ServiceOS.cs","lineNumber":400,"sourceCode":"                            //非空判断，若返回值为空，则为假\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                    {\n                        if (Query.IsCreated(serv_name))\n                        {\n                            //已经创建服务，才进行修改\n                            string cmd_modify_displayname = $\"sc config \\\"{serv_name}\\\" DisplayName=\\\"{serv_displayname}\\\"\";\n                            var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_displayname);","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/OdysseusYuan/LKY_OfficeTools/blob/6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf/LKY_OfficeTools/Common/Com_ServiceOS.cs#L382-L418","documentation":"Thrown in Com_ServiceOS.Config.Modify.BinPath's else-branch when Query.IsCreated(serv_name) is false at entry (Com_ServiceOS.cs:398-401), guarding against reconfiguring a service that is not registered. The throw is caught by BinPath's own catch and it returns false (Com_ServiceOS.cs:403-407).","triggerScenarios":"Calling Modify.BinPath before the service is created, after it was deleted, or with a name that does not case-insensitively match any GetServices() entry.","commonSituations":"Configuration step running before install on a clean machine; name drift after a rename; targeting DisplayName instead of ServiceName.","solutions":["Pre-check Query.IsCreated and create the service first if absent.","Verify the ServiceName with `sc query`.","Treat the false return as 'service not present; nothing to reconfigure'.","Order operations so Create always precedes Modify."],"exampleFix":"// before\nCom_ServiceOS.Config.Modify.BinPath(name, bin);\n\n// after\nif (Com_ServiceOS.Query.IsCreated(name))\n    Com_ServiceOS.Config.Modify.BinPath(name, bin);","handlingStrategy":"validation","validationCode":"if (Com_ServiceOS.Query.IsCreated(serv_name))\n    Com_ServiceOS.Config.Modify.BinPath(serv_name, serv_binpath);\n// else: nothing to reconfigure","typeGuard":"static bool ServiceRegistered(string name) => Com_ServiceOS.Query.IsCreated(name);","tryCatchPattern":null,"preventionTips":["Pre-check IsCreated before Modify; Create must precede Modify.","Treat the false return as 'service not present'.","Confirm ServiceName with `sc query`.","Order install before any configuration step."],"tags":["windows-service","scm","service-config","not-found"],"backgroundTag":null,"analyzedSha":"6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf","analyzedAt":"2026-08-13T18:00:34.810Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}