[AppleScript] 纯文本查看 复制代码
@echo off
:setup
set port=3389
set /p port=请输入新的远程桌面端口号并按回车确认:
REG ADD "HKLM\System\CurrentControlSet\Control\Terminal Server\Wds\Rdpwd\Tds\Tcp" /v PortNumber /t REG_DWORD /d %port% /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %port% /f
@echo 正在添加防火墙规则放行远程桌面端口
set firewallrulename=Allow Remote Desktop Port
netsh advfirewall firewall show rule name="%firewallrulename%" >nul
if not ERRORLEVEL 1 (
@echo 对不起,Firewall规则%firewallrulename%已经存在,将删除已存在相同名字的规则,重新创建Firewall规则放行远程桌面服务端口
netsh advfirewall firewall delete rule name="%firewallrulename%"
netsh advfirewall firewall add rule name="%firewallrulename%" dir=in protocol=tcp localport=%port% action=allow
) else (
@echo 新增Firewall放行远程桌面服务端口规则%firewallrulename%
netsh advfirewall firewall add rule name="%firewallrulename%" dir=in protocol=tcp localport=%port% action=allow
)
@echo 系统即将在10秒后重置远程桌面服务,将会断开远程连接,断开后请稍片刻然后使用新端口登陆
>nul ping 127.0.0.1 /n 10
net stop termservice /y && net start termservice >nul
@echo 远程端口已经修改完毕!请按任意键退出.请自行重启服务器然后用新端口号进入
pause