配置 Windows 上的远程连接永不超时可以让远程会话中运行的程序不会因为连接断开等原因而停止运行。如果 Windows Server 是 2008 R2 或以下版本的话,可以使用 Remote Desktop Session Host Configuration (tsconfig.msc) 进行配置;若是其他版本的 Windows Server,也可以直接运行以下命令配置注册表:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v fResetBroken /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v MaxConnectionTime /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v MaxDisconnectionTime /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v MaxIdleTime /t REG_DWORD /d 0 /f

或导入注册表配置文件

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]
"fResetBroken"=dword:00000000
"MaxConnectionTime"=dword:00000000
"MaxDisconnectionTime"=dword:00000000
"MaxIdleTime"=dword:00000000

若想在 Windows Server 2008 R2 以后的版本中使用 tsconfig.msctsadmin.msc 可以将以下文件从 Windows Server 2008 R2 中拷贝到目标系统:

C:\Windows\System32\tsadmin.dll
C:\Windows\System32\tsadmin.msc
C:\Windows\System32\tsconfig.dll
C:\Windows\System32\tsconfig.msc
C:\Windows\System32\umcRes.dll
C:\Windows\System32\wts.dll
C:\Windows\System32\en\tsadmin.resources.dll
C:\Windows\System32\en\tsconfig.resources.dll

或直接下载已导出的文件并解压至 C:\Windows\System32

注:若目标系统已存在 umcRes.dll,则无需覆盖。

拷贝完文件后,还需导入 tsconfigtsadmin 的注册表配置。

参考资料