将所有以下脚本复制到记事本中,并将其作为admin.cmd文件另存为桌面。右键单击它并以管理员身份运行。

它将提示一个菜单选择:
1.更改RDP端口(3389)
2.更改当前用户密码
3.重新启动计算机

@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 www.nat.ee
mode con: cols=36 lines=10
color 17
set "ing=ping -n 5 127.0.0.1 > nul"
set "rdp=HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules"

:Menu
cls
echo ==============================
echo.
echo 1.Change RDP Port (3389)
echo.
echo 2.Change Current User Password
echo.
echo 3.Reboot Computer
echo.
echo ==============================
choice /C:123 /N /M "Enter your choice [1,2,3]":
if errorlevel 3 goto:Restart
if errorlevel 2 goto:Password
if errorlevel 1 goto:RemotePort

:RemotePort
cls
echo Change RDP Port 3389
echo Press Enter to confirm.
set /P "Port=Scope(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 "%rdp%" /v "RemoteDesktop-UserMode-In-UDP" /t REG_SZ /d "v2.10|Action=Allow|Active=TRUE|Dir=In|Protocol=17|LPort=%Port%|App=%%SystemRoot%%\system32\svchost.exe|Svc=termservice|[email protected],-101|[email protected],-102|[email protected],-28852|" /f > nul
Reg add "%rdp%" /v "RemoteDesktop-In-TCP" /t REG_SZ /d "v2.10|Action=Allow|Active=TRUE|Dir=In|Protocol=6|LPort=%Port%|App=System|[email protected],-28753|[email protected],-28756|[email protected],-28752|" /f > nul
Reg add "%rdp%" /v "RemoteDesktop-UserMode-In-TCP" /t REG_SZ /d "v2.10|Action=Allow|Active=TRUE|Dir=In|Protocol=6|LPort=%Port%|App=%%SystemRoot%%\system32\svchost.exe|Svc=termservice|[email protected],-28853|[email protected],-28856|[email protected],-28852|" /f > nul
cls
echo Change Succeed!
echo Please remember your new Remote Desktop Port: %Port%
echo Reboot computer to take this change effect.
%ing% && goto:Menu) else (echo Wrong Port,%Port% larger than required scope,Please choose in "1-65535" range.
%ing% && goto:RemotePort)

:Password
cls
echo Change current user: %username% password
echo Press Enter to confirm
set /p pwd1=Please enter your new password:
cls
echo Press Enter to confirm
set /p pwd2=Please enter your new password again:
if "%pwd1%"=="%pwd2%" (
net user %username% %pwd2% > nul
cls
echo Change succeed. Please remember your new password.
%ing% && goto:Menu)else (cls
echo Password is wrong, please enter it again.
%ing% && goto:Password)

:Restart
shutdown.exe /r /f /t 0

另一个更改RDP端口的脚本并为新端口添加防火墙规则。

@echo off
color f0
echo 修改远程桌面3389端口(支持Windows 2003 2008 2008R2 2012 2012R2 7 8 10 )
echo 自动添加防火墙规则
echo %date%   %time%
echo    ARK 
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%"
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
echo 修改成功
echo 重启后生效,按任意键重启
pause
shutdown /r /t 0
exit
:end
echo 修改失败
pause

经过 jonny.

发表评论