Steam 可能无法启动应用程序,因为包括 OpenSSH 服务器在内的 Windows 服务无法访问桌面,因此无法启动 GUI 应用程序。据推测,Steam 不希望在无法与桌面交互的环境中运行应用程序,而这正是最终导致 Steam 崩溃的原因。 (诚然,这只是一种猜测——当崩溃似乎没有出现在日志或崩溃转储中时,很难确定究竟发生了什么。)
您可以在domih 到domih 到this question 中看到有关在 Windows 上通过 SSH 运行 GUI 应用程序时服务器作为 Windows 服务运行时为什么通过 SSH 启动 GUI 应用程序失败的更详细解释。
domih 还提出了一些解决方法。如果您可以选择,最简单的方法可能是手动下载并运行 OpenSSH 服务器,而不是将服务器作为服务运行。您可以找到最新版本的 Win32-OpenSSH/Windows for OpenSSH here。
另一个似乎仍然有效的解决方法是使用schtasks。这个想法是创建一个运行您的命令的计划任务——任务计划程序可以访问桌面。不幸的是,如果您不介意至少等到下一分钟,这只是一个可接受的解决方案; schtasks 只能将任务安排在精确的时间。此外,为了随时安全运行,代码可能应该将任务安排在至少一分钟后,这意味着等待时间可能在 1 到 2 分钟之间。
这种方法还有其他缺点。例如,以这种方式监控正在运行的进程可能更难。但是,在某些情况下它可能是一个可接受的解决方案,因此我编写了一些 Python 代码,可用于运行带有 schtasks 的程序,并附有示例。代码依赖于shortuuid 包;在尝试示例之前,您需要安装它。
import subprocess
import tempfile
import shortuuid
import datetime
def run_with_schtasks_soon(s, delay=2):
"""
Run a program with schtasks with a delay of no more than
delay minutes and no less than delay - 1 minutes.
"""
# delay needs to be no less than 2 since, at best, we
# could be calling subprocess at the end of the minute.
assert delay >= 2
task_name = shortuuid.uuid()
temp_file = tempfile.NamedTemporaryFile(mode="w", suffix=".bat", delete=False)
temp_file.write('{}\nschtasks /delete /tn {} /f\ndel "{}"'.format(s, task_name, temp_file.name))
temp_file.close()
run_time = datetime.datetime.now() + datetime.timedelta(minutes=delay)
time_string = run_time.strftime("%H:%M")
# This is locale-specific. You will need to change this to
# match your locale. (locale.setlocale and the "%x" format
# does not seem to work here)
date_string = run_time.strftime("%m/%d/%Y")
return subprocess.run("schtasks /create /tn {} /tr {} /sc once /st {} /sd {}".format(task_name,
temp_file.name,
time_string,
date_string),
shell=True)
if __name__ == "__main__":
# Runs The Witness (if you have it)
run_with_schtasks_soon("start steam://rungameid/210970")