OdysseusYuan/LKY_OfficeTools · warning · Exception

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

Error message

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

What it means

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

Source

Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:400

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

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

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

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 the false return as 'service not present; nothing to reconfigure'.
  4. Order operations so Create always precedes Modify.

Example fix

// before
Com_ServiceOS.Config.Modify.BinPath(name, bin);

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

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: 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.

Common situations: Configuration step running before install on a clean machine; name drift after a rename; targeting DisplayName instead of ServiceName.

Related errors


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