OdysseusYuan/LKY_OfficeTools · error · Exception
修改服务 {serv_name} 的 binPath 信息为 {serv_binpath} 失败!
Error message
修改服务 {serv_name} 的 binPath 信息为 {serv_binpath} 失败! What it means
Thrown in Com_ServiceOS.Config.Modify.BinPath when the `sc config ... binPath=` stdout lacks the success markers 成功/success (Com_ServiceOS.cs:388-396). This is the genuine sc rejection path: sc ran and reported an error. Common sc failures are an invalid/missing executable path in binPath or access-denied. The throw is caught by BinPath's catch and it returns false (Com_ServiceOS.cs:403-407).
Source
Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:395
{
//已经创建服务,才进行修改
string cmd_modify_binpath = $"sc config \"{serv_name}\" binPath=\"{serv_binpath}\"";
var modify_result = Com_ExeOS.Run.Cmd(cmd_modify_binpath);
//非空判断,若返回值为空,则为假
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
{View on GitHub (pinned to 6f9a1bd471)
Solutions
- Run elevated; sc config requires administrator privileges.
- Verify the new binPath file exists and quote paths containing spaces.
- Check the bool return and the logged sc output to read the exact failure reason.
- Use `sc qc <name>` afterwards to confirm the binPath was actually applied.
Example fix
// before
Com_ServiceOS.Config.Modify.BinPath(name, @"C:\Program Files\App\svc.exe");
// after
string bin = File.Exists(@"C:\Program Files\App\svc.exe") ? @"C:\Program Files\App\svc.exe" : null;
if (bin == null) { /* fix path first */ return false; }
Com_ServiceOS.Config.Modify.BinPath(name, bin); Defensive patterns
Strategy: validation
Validate before calling
string bin = File.Exists(serv_binpath) ? serv_binpath : null;
if (bin == null) { /* fix path first */ return false; }
bool ok = Com_ServiceOS.Config.Modify.BinPath(serv_name, bin); Type guard
static bool ValidBinPath(string p) => !string.IsNullOrWhiteSpace(p) && File.Exists(p);
Prevention
- Verify the new binPath file exists and quote paths containing spaces.
- Run elevated; sc config requires administrator privileges.
- Check the bool return of BinPath and the logged sc output.
- Confirm with `sc qc <name>` after a successful change.
When it happens
Trigger: Setting binPath to a non-existent file, a path the SCM cannot resolve (e.g. unquoted path with spaces, missing .exe), or calling without admin rights (sc config requires elevation).
Common situations: Migrating a service binary to a new install folder that does not yet exist; path with spaces passed unquoted into binPath; non-elevated reconfiguration tool.
Related errors
- 执行修改 {serv_name} binPath 参数时,返回值为空!
- 尝试修改服务 {serv_name} 的 binPath 信息为 {serv_binpath},但该服务未安装!
- 执行修改 {serv_name} DisplayName 参数时,返回值为空!
- 修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname} 失败!
- 尝试修改服务 {serv_name} 的 DisplayName 信息为 {serv_displayname},但该服务
AI-assisted analysis of OdysseusYuan/LKY_OfficeTools@6f9a1bd471 (2026-08-13).
Data as JSON: /api/errors/af9a58b5847ae922.
Report an issue: GitHub.