一键修改Windows远程桌面3389端口与用户密码的bat批处理脚本

2020-01-14T11:09:00

bat批处理脚本就能完成修改Windows远程桌面3389端口与用户密码,DD完Windows系统后,能够简单的修改远程端口。

 

@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
title 修改远程端口与用户密码
mode con: cols=55 lines=10
color 17
set "ing=ping -n 5 127.0.0.1 > nul"
:Menu
cls
echo ==============================
echo.
echo 1.修改远程端口
echo.
echo 2.修改用户密码
echo.
echo 3.重启计算机
echo.
echo ==============================
choice /C:123 /N /M "请输入你的选项 [1,2,3]:"
if errorlevel 3 goto:Restart
if errorlevel 2 goto:Password
if errorlevel 1 goto:RemotePort
:RemotePort
cls
set /P "Port=自定义远程桌面端口(1-65535): "
if %Port% leq 65535 (
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v "PortNumber" /t REG_DWORD /d "%Port%" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v "PortNumber" /t REG_DWORD /d "%Port%" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{338933891-3389-3389-3389-338933893389}" /t REG_SZ /d "v2.29|Action=Allow|Active=TRUE|Dir=In|Protocol=6|LPort=%Port%|Name=Remote Desktop(TCP-In)|" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{338933892-3389-3389-3389-338933893389}" /t REG_SZ /d "v2.29|Action=Allow|Active=TRUE|Dir=In|Protocol=17|LPort=%Port%|Name=Remote Desktop(UDP-In)|" /f > nul
echo 修改成功
echo 请牢记,你的远程端口是: %Port%
echo 重启计算机生效
%ing% && goto:Menu) else (echo 错误的端口,%Port% 大于所设置的范围,请在"1-65535"内。
%ing% && goto:RemotePort)
:Password
cls
echo 当前修改Administrator用户密码
set /p pwd1=请输入密码:
cls
set /p pwd2=请再次输入密码:
if "%pwd1%"=="%pwd2%" (
net user Administrator %pwd2% > nul
echo 修改成功,请牢记你的密码。
%ing% && goto:Menu)else (echo 密码错误,请重新输入。
%ing% && goto:Password)
:Restart
shutdown.exe /r /f /t 0

另存为 3389.bat 脚本即可,收藏备用。

!注意记事本编码要选择 ANSI,不然会乱码

这个可以修改3389端口,还能添加修改的远程端口到防火墙中放行。

感谢hostloc老司机提供。

 via.https://www.mou.pw/thread-293.htm

如果还是乱码 试试下面的英文版本:

@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
title Modify Remote Port and User Password
mode con: cols=55 lines=10
color 17
set "ing=ping -n 5 127.0.0.1 > nul"
:Menu
cls
echo ==============================
echo.
echo 1. Modify Remote Port
echo.
echo 2. Change User Password
echo.
echo 3. Restart Computer
echo.
echo ==============================
choice /C:123 /N /M "Please enter your option [1,2,3]:"
if errorlevel 3 goto:Restart
if errorlevel 2 goto:Password
if errorlevel 1 goto:RemotePort
:RemotePort
cls
set /P "Port=Customize the remote desktop port (1-65535):"
if %Port% leq 65535 (
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v "PortNumber" /t REG_DWORD /d "%Port%" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v "PortNumber" /t REG_DWORD /d "%Port%" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{338933891-3389-3389-3389-338933893389}" /t REG_SZ /d "v2.29|Action=Allow|Active=TRUE|Dir=In|Protocol=6|LPort=%Port%|Name=Remote Desktop(TCP-In)|" /f > nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /v "{338933892-3389-3389-3389-338933893389}" /t REG_SZ /d "v2.29|Action=Allow|Active=TRUE|Dir=In|Protocol=17|LPort=%Port%|Name=Remote Desktop(UDP-In)|" /f > nul
echo Port successfully modified
echo Please remember, your remote port is: %Port%
echo The computer needs to be restarted to take effect
%ing% && goto:Menu) else (echo Error port, %Port% is greater than the set range, please be within "1-65535".
%ing% && goto:RemotePort)
:Password
cls
echo Currently changing the Administrator user password
set /p pwd1=Please enter password:
cls
set /p pwd2=Please re-enter password:
if "%pwd1%"=="%pwd2%" (
net user Administrator %pwd2% > nul
echo Password successfully changed, please remember your password.
%ing% && goto:Menu)else (echo Password error, please re-enter.
%ing% && goto:Password)
:Restart
shutdown.exe /r /f /t 0

 

 

 

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »