OdysseusYuan/LKY_OfficeTools · error · Exception

修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败!

Error message

修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败!

What it means

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).

Source

Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:433

                        {
                            //已经创建服务,才进行修改
                            string cmd_modify_displayname = $"sc config \"{serv_name}\" DisplayName=\"{serv_displayname}\"";
                            var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_displayname);

                            //非空判断,若返回值为空,则为假
                            if (string.IsNullOrEmpty(modify_result))
                            {
                                throw new Exception($"执行修改 {serv_name} DisplayName 参数时,返回值为空!");
                            }

                            //判断是否修改 DisplayName 成功
                            if (modify_result.Contains("成功") || modify_result.ToLower().Contains("success"))
                            {
                                return true;
                            }
                            else
                            {
                                throw new Exception($"修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败!");
                            }
                        }
                        else
                        {
                            throw new Exception($"尝试修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname},但该服务未安装!");
                        }
                    }
                    catch (Exception Ex)
                    {
                        new Log(Ex.ToString());
                        return false;
                    }
                }

                internal static bool Description(string serv_name, string serv_description)
                {
                    try
                    {

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Run elevated; sc config requires administrator privileges.
  2. Avoid reserved/illegal characters in the DisplayName value.
  3. Check the bool return and the logged sc output for the exact error.
  4. Retry after elevating; confirm with `sc qc <name>`.

Example fix

// before
Com_ServiceOS.Config.Modify.DisplayName(name, display);

// after
bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display);
if (!ok) { /* elevate and retry; see log for sc error */ }
Defensive patterns

Strategy: validation

Validate before calling

bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display);
if (!ok) { /* elevate and retry; see log for sc error */ }

Prevention

When it happens

Trigger: Calling Modify.DisplayName without admin rights (sc config requires elevation), or with malformed arguments that sc rejects.

Common situations: Non-elevated service-management tool; DisplayName containing characters sc rejects; reconfiguration during SCM busy state.

Related errors


AI-assisted analysis of OdysseusYuan/LKY_OfficeTools@6f9a1bd471 (2026-08-13). Data as JSON: /api/errors/d83188bdb6d09d34. Report an issue: GitHub.