OdysseusYuan/LKY_OfficeTools · error · Exception
执行修改 {serv_name} 描述信息时,返回值为空!
Error message
执行修改 {serv_name} 描述信息时,返回值为空! What it means
Thrown in Com_ServiceOS.Config.Modify.Description when the stdout from `sc description ...` via Run.Cmd is null or empty (Com_ServiceOS.cs:459-461). Run.Cmd returns null only inside its catch, so this indicates a cmd.exe/redirect infrastructure failure rather than an sc error. Description catches the throw, logs it, and returns false (Com_ServiceOS.cs:479-483).
Source
Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:461
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);
//非空判断,若返回值为空,则为假
if (string.IsNullOrEmpty(modify_result))
{
throw new Exception($"执行修改 {serv_name} 描述信息时,返回值为空!");
}
//判断是否修改描述成功
if (modify_result.Contains("成功") || modify_result.ToLower().Contains("success"))
{
return true;
}
else
{
throw new Exception($"修改服务 {serv_name} 的描述信息为 {serv_description} 失败!");
}
}
else
{
throw new Exception($"尝试修改服务 {serv_name} 的描述信息为 {serv_description},但该服务未安装!");
}
}
catch (Exception Ex)View on GitHub (pinned to 6f9a1bd471)
Solutions
- Ensure cmd.exe is on PATH and not blocked; run elevated.
- Run `sc description <name> "..."` directly in a console to confirm sc works.
- Inspect the bool return and Lib_AppLog for Run.Cmd's caught exception.
- Resolve the cmd/redirect environment then retry.
Example fix
// before
bool ok = Com_ServiceOS.Config.Modify.Description(name, desc);
// after
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.Description(name, desc); Defensive patterns
Strategy: validation
Validate before calling
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.Description(name, desc); Type guard
static bool ServiceRegistered(string name) => Com_ServiceOS.Query.IsCreated(name);
Prevention
- Description 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 description.
- Reproduce `sc description <name> "..."` 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 producing stdout.
Common situations: cmd.exe blocked by policy on a hardened host; stdio handle exhaustion; antivirus hooking redirected console IO.
Related errors
- 执行修改 {serv_name} binPath 参数时,返回值为空!
- 执行修改 {serv_name} DisplayName 参数时,返回值为空!
- 创建服务 {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/f03e43c16ad6f5c0.
Report an issue: GitHub.