OdysseusYuan/LKY_OfficeTools · error · Exception
执行修改 {serv_name} binPath 参数时,返回值为空!
Error message
执行修改 {serv_name} binPath 参数时,返回值为空! What it means
Thrown in Com_ServiceOS.Config.Modify.BinPath when the stdout from `sc config ... binPath=...` via Run.Cmd is null or empty (Com_ServiceOS.cs:383-385). Run.Cmd only returns null from its catch, so this indicates a cmd.exe/redirect infrastructure failure rather than an sc rejection (which still prints text). BinPath catches the throw, logs it, and returns false (Com_ServiceOS.cs:403-407).
Source
Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:385
}
}
internal class Modify
{
internal static bool BinPath(string serv_name, string serv_binpath)
{
try
{
if (Query.IsCreated(serv_name))
{
//已经创建服务,才进行修改
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)View on GitHub (pinned to 6f9a1bd471)
Solutions
- Ensure cmd.exe is available on PATH and not blocked; run elevated.
- Run the exact `sc config <name> binPath=...` in a console to confirm sc works.
- Check the bool return of BinPath and the Lib_AppLog entry for Run.Cmd's caught exception.
- Retry after resolving the cmd/redirect environment issue.
Example fix
// before
bool ok = Com_ServiceOS.Config.Modify.BinPath(name, bin);
// after
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.BinPath(name, bin); Defensive patterns
Strategy: validation
Validate before calling
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.BinPath(name, bin); Type guard
static bool ServiceRegistered(string name) => Com_ServiceOS.Query.IsCreated(name);
Prevention
- BinPath swallows the throw and returns false; check the bool return and log.
- Ensure cmd.exe is reachable and not blocked by policy.
- Run elevated before issuing sc config.
- Reproduce `sc config <name> binPath=...` in a console when debugging.
When it happens
Trigger: Run.Cmd throws: cmd.exe cannot start, output redirection fails, or the process is killed before emitting stdout.
Common situations: cmd.exe blocked by policy on a locked-down machine; stdio handle exhaustion; security tool intercepting redirected console IO.
Related errors
- 执行修改 {serv_name} DisplayName 参数时,返回值为空!
- 执行修改 {serv_name} 描述信息时,返回值为空!
- 创建服务 {serv_name} 时,返回值为空!
- 删除服务 {serv_name} 时,返回值为空!
- 修改服务 {serv_name} 的 binPath 信息为 {serv_binpath} 失败!
AI-assisted analysis of OdysseusYuan/LKY_OfficeTools@6f9a1bd471 (2026-08-13).
Data as JSON: /api/errors/d80a2001abd4607f.
Report an issue: GitHub.