OdysseusYuan/LKY_OfficeTools · error · Exception
执行修改 {serv_name} DisplayName 参数时,返回值为空!
Error message
执行修改 {serv_name} DisplayName 参数时,返回值为空! What it means
Thrown in Com_ServiceOS.Config.Modify.DisplayName when the stdout from `sc config ... DisplayName=` via Run.Cmd is null or empty (Com_ServiceOS.cs:421-423). Run.Cmd returns null only from its catch, so this denotes a cmd.exe/redirect infrastructure failure, not an sc error (which still returns text). DisplayName catches the throw, logs it, and returns false (Com_ServiceOS.cs:441-445).
Source
Thrown at LKY_OfficeTools/Common/Com_ServiceOS.cs:423
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);
//非空判断,若返回值为空,则为假
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)View on GitHub (pinned to 6f9a1bd471)
Solutions
- Ensure cmd.exe is on PATH and not blocked; run elevated.
- Run `sc config <name> DisplayName=...` directly in a console to confirm sc works.
- Inspect the bool return and Lib_AppLog for Run.Cmd's caught exception.
- Fix the cmd/redirect environment then retry.
Example fix
// before
bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display);
// after
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display); Defensive patterns
Strategy: validation
Validate before calling
if (!Com_ServiceOS.Query.IsCreated(name)) { return false; }
bool ok = Com_ServiceOS.Config.Modify.DisplayName(name, display); Type guard
static bool ServiceRegistered(string name) => Com_ServiceOS.Query.IsCreated(name);
Prevention
- DisplayName 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> DisplayName=...` in a console when debugging.
When it happens
Trigger: Run.Cmd throws because cmd.exe cannot launch, output redirection fails, or the process is killed before producing stdout.
Common situations: cmd.exe blocked by AppLocker/WDAC on a hardened host; stdio handle exhaustion; antivirus hooking redirected console output.
Related errors
- 执行修改 {serv_name} binPath 参数时,返回值为空!
- 执行修改 {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/b54f82a70fd83a8b.
Report an issue: GitHub.