{"record":{"id":"d83188bdb6d09d34","repo":"OdysseusYuan/LKY_OfficeTools","slug":"serv-name-displayname-serv-displayna","errorCode":null,"errorMessage":"修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败！","messagePattern":"修改服务 (.+?) 的 DisplayName 信息为 (.+?) 失败！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LKY_OfficeTools/Common/Com_ServiceOS.cs","lineNumber":433,"sourceCode":"                        {\n                            //已经创建服务，才进行修改\n                            string cmd_modify_displayname = $\"sc config \\\"{serv_name}\\\" DisplayName=\\\"{serv_displayname}\\\"\";\n                            var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_displayname);\n\n                            //非空判断，若返回值为空，则为假\n                            if (string.IsNullOrEmpty(modify_result))\n                            {\n                                throw new Exception($\"执行修改 {serv_name} DisplayName 参数时，返回值为空！\");\n                            }\n\n                            //判断是否修改 DisplayName 成功\n                            if (modify_result.Contains(\"成功\") || modify_result.ToLower().Contains(\"success\"))\n                            {\n                                return true;\n                            }\n                            else\n                            {\n                                throw new Exception($\"修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败！\");\n                            }\n                        }\n                        else\n                        {\n                            throw new Exception($\"尝试修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname}，但该服务未安装！\");\n                        }\n                    }\n                    catch (Exception Ex)\n                    {\n                        new Log(Ex.ToString());\n                        return false;\n                    }\n                }\n\n                internal static bool Description(string serv_name, string serv_description)\n                {\n                    try\n                    {","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/OdysseusYuan/LKY_OfficeTools/blob/6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf/LKY_OfficeTools/Common/Com_ServiceOS.cs#L415-L451","documentation":"Thrown in Com_ServiceOS.Config.Modify.DisplayName when the `sc config ... DisplayName=` stdout lacks the success markers 成功/success (Com_ServiceOS.cs:427-434). This is the genuine sc rejection path; most often access-denied from a non-elevated caller. The throw is caught by DisplayName's catch and it returns false (Com_ServiceOS.cs:441-445).","triggerScenarios":"Calling Modify.DisplayName without admin rights (sc config requires elevation), or with malformed arguments that sc rejects.","commonSituations":"Non-elevated service-management tool; DisplayName containing characters sc rejects; reconfiguration during SCM busy state.","solutions":["Run elevated; sc config requires administrator privileges.","Avoid reserved/illegal characters in the DisplayName value.","Check the bool return and the logged sc output for the exact error.","Retry after elevating; confirm with `sc qc <name>`."],"exampleFix":"// before\nCom_ServiceOS.Config.Modify.DisplayName(name, display);\n\n// after\nbool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display);\nif (!ok) { /* elevate and retry; see log for sc error */ }","handlingStrategy":"validation","validationCode":"bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display);\nif (!ok) { /* elevate and retry; see log for sc error */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run elevated; sc config requires administrator privileges.","Avoid reserved/illegal characters in the DisplayName.","Check the bool return and the logged sc output for the exact reason.","Confirm with `sc qc <name>` after a successful change."],"tags":["windows-service","scm","service-config","access-denied"],"backgroundTag":null,"analyzedSha":"6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf","analyzedAt":"2026-08-13T18:00:34.810Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}