Modify the Windows default remote port number

background

  • Requirements: Modify the Windows default remote port number, and add firewall rules
  • Operating System: Windows 7,8,10, Windows Server 2003,2008,2008 R2,2012,2012 R2,2016

Implementation steps

  1. Positioning the registry, [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Terminal Server \ Wds \ rdpwd \ Tds \ tcp], modify the value of the right side PortNumber choose decimal, the default port number 3389 changes to other desired port number ( 1-65535), such as: 55399;
  2. Reposition the registry, [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentContro1Set \ Control \ Tenninal Server \ WinStations \ RDP-Tcp], modify the value of the right side of PortNumber, select Decimal, the port number of the same port number appeal, twice modified port number must be the same;
  3. New Firewall inbound rule will set the port number of the release, and turn off the default port 3389 Remote rules;
  4. Take effect after restart "Remote Desktop Services" service or restart the computer.

bat batch

@echo off
color 02
echo 修改远程桌面3389端口(支持Windows 2003、2008、2008 R2、2012、2012 R2、7、8、10 ,Windwos 7及以上系统请以管理员身份运行)  
echo.
echo 自动添加防火墙规则
echo %date%   %time%
echo.
set /p c= 请输入新的端口:
if "%c%"=="" goto end:
goto edit: 
: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\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
net stop TermService
net start TermService
echo.
echo 修改成功!
echo.
pause
exit
:end
echo 修改失败!
echo.
pause

Guess you like

Origin www.cnblogs.com/nethrd/p/10973211.html