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 @ 2024-08-16 18:00  wanghongwei-dev  阅读(76)  评论(0编辑  收藏  举报