@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.修改远程端口
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
echo 修改远程桌面端口
echo 按回车键(Enter)确定
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 "%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|Name=@RdpGroupPolicyExtension.dll,-101|Desc=@RdpGroupPolicyExtension.dll,-102|EmbedCtxt=@FirewallAPI.dll,-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|Name=@FirewallAPI.dll,-28753|Desc=@FirewallAPI.dll,-28756|EmbedCtxt=@FirewallAPI.dll,-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|Name=@FirewallAPI.dll,-28853|Desc=@FirewallAPI.dll,-28856|EmbedCtxt=@FirewallAPI.dll,-28852|" /f > nul
cls
echo 修改成功
echo 请牢记，你的远程端口是: %Port% 
echo 重启计算机生效
%ing% && goto:Menu) else (echo 错误的端口，%Port% 大于所设置的范围，请在"1-65535"内。
%ing% && goto:RemotePort)
:Password
cls
echo 当前修改用户： %username% 密码
echo 按回车键(Enter)确定
set /p pwd1=请输入密码：
cls
echo 按回车键(Enter)确定
set /p pwd2=请再次输入密码：
if "%pwd1%"=="%pwd2%" (
net user %username% %pwd2% > nul
cls
echo 修改成功，请牢记你的密码。
%ing% && goto:Menu)else (cls
echo 密码错误，请重新输入。
%ing% && goto:Password)
:Restart
shutdown.exe /r /f /t 0