修改windows的远程桌面rdp协议的端口3389为其他端口

修改windows的远程桌面rdp协议的端口3389为其他端口

金箍棒

#rdp #3389 #远程桌面


前言

windows在公网上总是被扫3389端口,修改一下端口

操作方法

复制下面的代码端,在windows中存为bat文件,例如[3389.bat];

然后直接运行bat,输入自定义的端口,再确认环节输入y,

如果不确认,在15秒后会自动恢复原来的配置

@echo off
setlocal enabledelayedexpansion
color 0B

:: --- Check for Administrator Rights ---
openfiles >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting Administrative Privileges...
    powershell -Command "Start-Process -FilePath '%0' -Verb RunAs"
    exit /b
)

:: --- 1. Retrieve current RDP port from Registry ---
for /f "tokens=3" %%a in ('reg query "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber') do (
    set /a OLD_PORT=%%a
)

echo ========================================================
echo Current RDP Port: %OLD_PORT%
set /p NEW_PORT="Enter NEW RDP port number (1024-65535): "

:: --- 2. Apply Changes ---
echo [1/3] Updating Registry...
reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %NEW_PORT% /f >nul
if %errorlevel% neq 0 (echo ERROR: Failed to update Registry. & pause & exit /b)

echo [2/3] Configuring Firewall Rule...
netsh advfirewall firewall add rule name="RDP_Temp_Port" dir=in action=allow protocol=TCP localport=%NEW_PORT% >nul

echo [3/3] Restarting Remote Desktop Services...
net stop TermService /y >nul
net start TermService >nul

echo ========================================================
echo Port changed to: %NEW_PORT%
echo WARNING: Test your connection NOW!
echo If no key is pressed within 15 seconds, 
echo the configuration will ROLLBACK to port: %OLD_PORT%
echo ========================================================

:: --- 3. Confirmation and Rollback Logic ---
choice /t 15 /d n /m "Do you want to keep these changes?"

if errorlevel 2 (
    echo [!] Timeout or Canceled. Rolling back...
    reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d %OLD_PORT% /f >nul
    netsh advfirewall firewall delete rule name="RDP_Temp_Port" >nul
    net stop TermService /y >nul
    net start TermService >nul
    echo [OK] Restored to original port: %OLD_PORT%
    pause
) else (
    echo [OK] Changes saved permanently.
    netsh advfirewall firewall set rule name="RDP_Temp_Port" new name="RDP-Custom-Port-%NEW_PORT%" >nul
    pause
)


相关阅读

甲骨文实例dd/救砖/vnc/教程

甲骨文实例dd windows教程(包含windows dd回linux教程)

【保姆级】甲骨文云ARM安装windows教程

★★★如果我想购买甲骨文账号有哪些渠道呢?

★★★甲骨文哪些区域可以手开arm机型?

4.甲骨文新注册的账号需要做点儿什么?怎么防止丢号?甲骨文拿到收来的账号(新收账号到手)需要做点儿什么?防止账号被找回!防止被盗号?

↓↓↓↓相关阅读-点击下方的链接查看更多↓↓↓↓

※※甲骨文遇到的一些问题的解决方案和处理办法※※

本系列的订阅频道->https://t.me/jingubang_sub


Report Page