OdysseusYuan/LKY_OfficeTools · warning · Exception

尝试修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname},但该服务

Error message

尝试修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname},但该服务未安装!

What it means

Thrown in Com_ServiceOS.Config.Modify.DisplayName's else-branch when Query.IsCreated(serv_name) is false at entry (Com_ServiceOS.cs:436-439), guarding against editing a non-existent service. The throw is caught by DisplayName's own catch and it returns false (Com_ServiceOS.cs:441-445).

Source

Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:438

                            //非空判断,若返回值为空,则为假
                            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
                    {
                        if (Query.IsCreated(serv_name))
                        {
                            //已经创建服务,才进行修改
                            string cmd_modify_desc = $"sc description \"{serv_name}\" \"{serv_description}\"";
                            var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_desc);

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Pre-check Query.IsCreated and Create the service first if absent.
  2. Verify the ServiceName with `sc query`.
  3. Treat false as 'service not present; nothing to change'.
  4. Order Create before Modify.

Example fix

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

// after
if (Com_ServiceOS.Query.IsCreated(name))
    Com_ServiceOS.Config.Modify.DisplayName(name, display);
Defensive patterns

Strategy: validation

Validate before calling

if (Com_ServiceOS.Query.IsCreated(serv_name))
    Com_ServiceOS.Config.Modify.DisplayName(serv_name, serv_displayname);
// else: nothing to reconfigure

Type guard

static bool ServiceRegistered(string name) => Com_ServiceOS.Query.IsCreated(name);

Prevention

When it happens

Trigger: Calling Modify.DisplayName for an unregistered, already-deleted, or misspelled service, or when GetServices throws so IsCreated returns false.

Common situations: Configuration step before install; name drift after a rename; using DisplayName where ServiceName was required.

Related errors


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