Windows操作系统远程桌面端口修改脚本

change_rdsport_CN.bat(支持Windows2003, 2008, 2008R2, 2012, 2012R2, 7, 8, 10)

@echo off
color f0
echo 修改远程桌面3389端口(支持Windows2003, 2008, 2008R2, 2012, 2012R2, 7, 8, 10)
echo 自动添加防火墙规则

set /p c=请输入新的端口:
if "%c%"=="" goto end

:edit
netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%"
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v PortNumber /t REG_DWORD /d %c% /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %c% /f

echo 修改成功

:confirm
set /p restart=重启后生效,是否立即重启? (Y/y确认, 其他键跳过重启):
if /I "%restart%"=="Y" (
    shutdown /r /t 0
) else (
    echo 已跳过重启
)

:end
pause

change_rdsport_CN.bat(支持Windows Server 2016, 2019, 2022)

@echo off
color f0
echo 修改远程桌面3389端口(支持Windows Server 2016, 2019, 2022)
echo 自动添加防火墙规则

set /p c=请输入新的端口:
if "%c%"=="" goto end

:edit
netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %c% /f

echo 修改成功

:confirm
set /p restart=重启后生效,是否立即重启? (Y/y确认, 其他键跳过重启):
if /I "%restart%"=="Y" (
    shutdown /r /t 0
) else (
    echo 已跳过重启
)

:end
pause

change_rdsport_EN.bat(supports Windows 2003, 2008, 2008R2, 2012, 2012R2, 7, 8, 10)

@echo off
color f0
echo Modify Remote Desktop Port 3389 (supports Windows 2003, 2008, 2008R2, 2012, 2012R2, 7, 8, 10)
echo Automatically add firewall rules

set /p c=Please enter the new port:
if "%c%"=="" goto end

:edit
netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%"
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v PortNumber /t REG_DWORD /d %c% /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %c% /f

echo Modification successful

:confirm
set /p restart=Changes will take effect after reboot. Do you want to reboot now? (Y/y to confirm, any other key to skip reboot):
if /I "%restart%"=="Y" (
    shutdown /r /t 0
) else (
    echo Reboot skipped
)

:end
pause

change_rdsport_EN.bat(supports Windows server 2016, 2019, 2022)

@echo off
color f0
echo Modify Remote Desktop Port 3389 (supports Windows server 2016, 2019, 2022)
echo Automatically add firewall rules

set /p c=Please enter the new port:
if "%c%"=="" goto end

:edit
netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %c% /f

echo Modification successful

:confirm
set /p restart=Changes will take effect after reboot. Do you want to reboot now? (Y/y to confirm, any other key to skip reboot):
if /I "%restart%"=="Y" (
    shutdown /r /t 0
) else (
    echo Reboot skipped
)

:end
pause

posted @   wanghongwei-dev  阅读(146)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
历史上的今天:
2023-08-16 Iptables mangle表和raw表应用场景介绍
点击右上角即可分享
微信分享提示