每次regedit打开注册表修改3389端口都觉得麻烦,推荐你使用修改3389端口脚本!脚本如下:
@echo off rem 查找端口号 for /f "skip=4 tokens=3 delims= " %%i in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber') do (set value16=%%i) set value=%value16:~2% rem echo %value% setlocal EnableDelayedExpansion set "str=0123456789ABCDEF" for /l %%a in (0 1 15) do ( set -%%a=!str:~%%a,1! set -!str:~%%a,1!=%%a ) for /l %%a in (0 1 100) do ( if not "!value:~%%a,1!"=="" ( call set sun=%%-!value:~%%a,1!%% !sun! )) rem echo !sun! set /a nnn=1,num=0 for %%a in (!sun!) do ( rem set num0=!num! set /a num=%%a*nnn+num rem echo num = %%a*!nnn! + !num0! = !num! set /a nnn*=16 ) rem echo 当前远程桌面端口号为十六进制: %value16% 即 %value% echo 修改后重启生效,记得把新端口加入防火墙. rem setlocal DisableDelayedExpansion rem 以下是系统默认 goto xiugai @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenPorts\List" /v 3389:TCP /t REG_SZ /d 3389:TCP:*:Enabled:@xpsp2res.dll,-22009 /f :xiugai set PortNumber= set /p PortNumber=输入即将修改的十进制端口号(1024-65535): rem if "%PortNumber%"=="" exit if not defined PortNumber (set /a PortNumber=3389 & echo 未输入端口号,即将修改为默认值!PortNumber! & pause) echo %PortNumber%|findstr "^[0-9]*$" >nul || (echo 必须纯数字! & goto xiugai) if %PortNumber% lss 1024 (echo 端口号不能小于1024 & goto xiugai) if %PortNumber% gtr 65535 (echo 端口号不能大于65535 & goto xiugai) echo %PortNumber% rem 修改端口后开启 rem 总开关 @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f rem 修改端口号,默认会直接修改十进制值,注意:范围在1024到65535,而且不能冲突,事实上,只修改第二处WinStations那一个也是可以的。 @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v PortNumber /t REG_DWORD /d %PortNumber% /f @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %PortNumber% /f @reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenPorts\List /v !num!:TCP /f @reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenPorts\List" /v %PortNumber%:TCP /t REG_SZ /d %PortNumber%:TCP:*:Enabled:@xpsp2res.dll,-22009 /f
将以上代码保存为bat文件打开即可,如有不懂请留言!
本教程由铁网维原创出品 服务器运维官方网址http://www.tieww.com 欢迎大家多多关注本站 感谢大家的支持。