将下列代码保存为bat文件后运行


@echo off
color 0a
title  修改 Windows 远程桌面端口号
echo.
echo   输入您要更改的远程桌面端口号,范围:1024-65535,不能与其他端口冲突!
echo.
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
netsh advfirewall firewall set opmode mode = enable
netsh advfirewall firewall set portopening all 80 web enable
netsh advfirewall firewall set portopening all 3389 remote-pre enable
netsh advfirewall firewall set portopening all %port% remote enable
echo.
echo   重新启动远程桌面……
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t reg_dword /d 1 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t reg_dword /d 0 /f
echo.
echo   下面开始重新启动电脑以生效,请选择启动方式:
echo   选择1手动重新启动
echo   选择2自动重新启动
set /p select=请您选择 [ 1 或 2 ]:
if  "%select%"=="1"  goto A
if  "%select%"=="2"  goto B
pause
exit
:A
echo   退出,请手动重新启动电脑
pause
exit
:B
shutdown -r -t 1
pause
exit