You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell执行cmd.exe报CursorPositionError,求问题原因

问题描述

供应商自动化补丁流程的父脚本里包含如下语句:

cmd.exe /c <command>

执行时抛出以下错误:

PS>TerminatingError(): "Program 'cmd.exe' failed to run: The CursorPosition property is not implemented by PsSasRawUserInterface.At <pathToScript>.ps1:105 char:1
+ cmd.exe /c "RiposteService Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~."
Program 'cmd.exe' failed to run: The CursorPosition property is not implemented by PsSasRawUserInterface.At 
<pathToScript>.ps1:105 char:1
+ cmd.exe /c "RiposteService Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At <pathToScript>.ps1:105 char:1
+ cmd.exe /c "RiposteService Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed
Program 'cmd.exe' failed to run: The CursorPosition property is not
implemented by PsSasRawUserInterface.At <pathToScript>.ps1:105 char:1
+ cmd.exe /c "RiposteService Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At <pathToScript>.ps1:105 char:1
+ cmd.exe /c "RiposteService Stop"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedEx
   ception
    + FullyQualifiedErrorId : NativeCommandFailed

手动在PowerShell提示符执行相同命令无异常,直接将cmd.exe替换为目标可执行文件也会报相同错误。

可能的原因
  • 受限UI环境的交互限制
    错误中的PsSasRawUserInterface指向PowerShell的SAS安全会话环境,这类场景通常是无交互或UI受限的(比如自动化任务、服务账户上下文、远程执行)。当cmd.exe或目标程序尝试读取/修改控制台光标位置时,该环境不支持CursorPosition属性,直接触发报错。而手动执行是在完整的用户控制台会话中,不存在此限制。

  • 执行上下文的资源差异
    自动化补丁流程大概率以服务账户或非交互式会话运行,这类会话没有绑定完整的控制台窗口。PowerShell在非交互模式下处理原生程序的UI请求时,因缺少标准输入输出的控制台资源,会抛出该错误。手动执行是在用户交互式会话中,控制台资源齐全。

  • PowerShell版本或配置问题
    旧版PowerShell(如5.1及更早)在处理原生程序与受限UI环境的交互时存在兼容性bug。另外,若脚本中设置了$ErrorActionPreference = 'Stop',会将原本的非终止错误升级为终止错误,导致报错信息重复抛出。

  • 目标程序的控制台依赖
    替换成目标可执行文件仍报错,说明问题不在cmd.exe,而是RiposteService本身启动时会尝试访问控制台光标这类UI资源。在受限会话中,这类操作无法完成,进而触发错误。

内容的提问来源于stack exchange,提问作者Petr Kolin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 20:22:49