@ -2,39 +2,42 @@
@ echo off
@ echo off
setLocal EnableExtensions
setLocal EnableExtensions
setlocal EnableDelayedExpansion
setlocal EnableDelayedExpansion
: : _ _
REM -------------------------------------------------------------------
: : _ | | _ | | _
REM
: : ____ _ _| |_ ___ _ _ ____ _ | | ____| |_ ____ | | _ ____| |_
REM autoupdate.bat
: : / _ | | | | _)/ _ \| | | | _ \ / || |/ _ | _)/ _ ) | || \ / _ | _)
REM
: : ( ( | | |_| | |_| |_| | |_| | | | ( (_| ( ( | | |_( (/ / _| |_) ( ( | | |__
REM Automatic RDP Wrapper installer and updater // asmtron (2021-02-06)
: : \_||_|\____|\___\___/ \____| ||_/ \____|\_||_|\___\____(_|____/ \_||_|\___)
REM -------------------------------------------------------------------
: : |_|
REM Options:
: :
REM -log = redirect display output to the file autoupdate.log
: : Automatic RDP Wrapper installer and updater asmtron (2021-04-19)
REM -taskadd = add autorun of autoupdate.bat on startup in schedule task
: : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM -taskremove = remove autorun of autoupdate.bat on startup in schedule task
: : Options:
REM
: : -log = redirect display output to the file autoupdate.log
REM Info:
: : -taskadd = add autorun of autoupdate.bat on startup in schedule task
REM The autoupdater first use and check the official rdpwrap.ini.
: : -taskremove = remove autorun of autoupdate.bat on startup in schedule task
REM If a new termsrv.dll is not supported in the offical rdpwrap.ini,
: :
REM autoupdater first tries the asmtron rdpwrap.ini (disassembled and
: : Info:
REM tested by asmtron). The autoupdater will also use rdpwrap.ini files
: : The autoupdater first use and check the official rdpwrap.ini.
REM of other contributors like the one of "sebaxakerhtc, affinityv, DrDrrae, saurav-biswas".
: : If a new termsrv.dll is not supported in the offical rdpwrap.ini,
REM Extra rdpwrap.ini sources can also be defined...
: : autoupdater first tries the asmtron rdpwrap.ini (disassembled and
REM
: : tested by asmtron). The autoupdater will also use rdpwrap.ini files
REM { Special thanks to binarymaster and all other contributors }
: : of other contributors like the one of "sebaxakerhtc, affinityv, DrDrrae, saurav-biswas".
: : Extra rdpwrap.ini sources can also be defined...
REM -----------------------------------------
: :
REM Location of new/updated rdpwrap.ini files
: : { Special thanks to binarymaster and all other contributors }
REM -----------------------------------------
: :
: : -----------------------------------------
: : Location of new/updated rdpwrap.ini files
: : -----------------------------------------
set rdpwrap_ini_update_github_1 = " https://raw.githubusercontent.com/asmtron/rdpwrap/master/res/rdpwrap.ini "
set rdpwrap_ini_update_github_1 = " https://raw.githubusercontent.com/asmtron/rdpwrap/master/res/rdpwrap.ini "
set rdpwrap_ini_update_github_2 = " https://raw.githubusercontent.com/sebaxakerhtc/rdpwrap.ini/master/rdpwrap.ini "
set rdpwrap_ini_update_github_2 = " https://raw.githubusercontent.com/sebaxakerhtc/rdpwrap.ini/master/rdpwrap.ini "
set rdpwrap_ini_update_github_3 = " https://raw.githubusercontent.com/affinityv/INI-RDPWRAP/master/rdpwrap.ini "
set rdpwrap_ini_update_github_3 = " https://raw.githubusercontent.com/affinityv/INI-RDPWRAP/master/rdpwrap.ini "
set rdpwrap_ini_update_github_4 = " https://raw.githubusercontent.com/DrDrrae/rdpwrap/master/res/rdpwrap.ini "
set rdpwrap_ini_update_github_4 = " https://raw.githubusercontent.com/DrDrrae/rdpwrap/master/res/rdpwrap.ini "
set rdpwrap_ini_update_github_5 = " https://raw.githubusercontent.com/saurav-biswas/rdpwrap-1/master/res/rdpwrap.ini "
set rdpwrap_ini_update_github_5 = " https://raw.githubusercontent.com/saurav-biswas/rdpwrap-1/master/res/rdpwrap.ini "
REM set rdpwrap_ini_update_github_6="https://raw.githubusercontent.com/....Extra.6...."
: : set rdpwrap_ini_update_github_6="https://raw.githubusercontent.com/....Extra.6...."
REM set rdpwrap_ini_update_github_7="https://raw.githubusercontent.com/....Extra.7...."
: : set rdpwrap_ini_update_github_7="https://raw.githubusercontent.com/....Extra.7...."
: :
set autoupdate_bat = " %~dp0 autoupdate.bat "
set autoupdate_bat = " %~dp0 autoupdate.bat "
set autoupdate_log = " %~dp0 autoupdate.log "
set autoupdate_log = " %~dp0 autoupdate.log "
set RDPWInst_exe = " %~dp0 RDPWInst.exe "
set RDPWInst_exe = " %~dp0 RDPWInst.exe "
@ -43,16 +46,16 @@ set rdpwrap_ini_check=%rdpwrap_ini%
set rdpwrap_new_ini = " %~dp0 rdpwrap_new.ini "
set rdpwrap_new_ini = " %~dp0 rdpwrap_new.ini "
set github_location = 1
set github_location = 1
set retry_network_check = 0
set retry_network_check = 0
: :
echo ___________________________________________
echo ___________________________________________
echo Automatic RDP Wrapper installer and updater
echo Automatic RDP Wrapper installer and updater
echo .
echo .
echo ^< check if the RDP Wrapper is up-to-date and working^>
echo ^< check if the RDP Wrapper is up-to-date and working^>
echo .
echo .
REM check if admin
: : check if admin
fsutil dirty query %systemdrive% > nul
fsutil dirty query %systemdrive% > nul
if not %errorlevel% == 0 goto : not_admin
if not %errorlevel% == 0 goto : not_admin
REM check for arguments
: : check for arguments
if /i " %~1 " == " -log " (
if /i " %~1 " == " -log " (
echo %autoupdate_bat% output from %date% at %time% > %autoupdate_log%
echo %autoupdate_bat% output from %date% at %time% > %autoupdate_log%
call %autoupdate_bat% >> %autoupdate_log%
call %autoupdate_bat% >> %autoupdate_log%
@ -61,6 +64,7 @@ if /i "%~1"=="-log" (
if /i " %~1 " == " -taskadd " (
if /i " %~1 " == " -taskadd " (
echo [+] add autorun of %autoupdate_bat% on startup in the schedule task.
echo [+] add autorun of %autoupdate_bat% on startup in the schedule task.
schtasks /create /f /sc ONSTART /tn " RDP Wrapper Autoupdate " /tr " cmd.exe /C \ " %~dp0 autoupdate.bat\" -log " /ru SYSTEM /delay 0000:10
schtasks /create /f /sc ONSTART /tn " RDP Wrapper Autoupdate " /tr " cmd.exe /C \ " %~dp0 autoupdate.bat\" -log " /ru SYSTEM /delay 0000:10
powershell " $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries; Set-ScheduledTask -TaskName 'RDP Wrapper Autoupdate' -Settings $settings "
goto : finish
goto : finish
)
)
if /i " %~1 " == " -taskremove " (
if /i " %~1 " == " -taskremove " (
@ -76,10 +80,10 @@ if /i not "%~1"=="" (
echo -taskremove = remove autorun of autoupdate.bat on startup in the schedule task
echo -taskremove = remove autorun of autoupdate.bat on startup in the schedule task
goto : finish
goto : finish
)
)
REM check if file "RDPWInst.exe" exist
: : check if file "RDPWInst.exe" exist
if not exist %RDPWInst_exe% goto : error_install
if not exist %RDPWInst_exe% goto : error_install
goto : start_check
goto : start_check
: :
: not_admin
: not_admin
color 0e
color 0e
echo ___________________________________
echo ___________________________________
@ -94,21 +98,21 @@ echo [-] RDP Wrapper installer executable (RDPWInst.exe) not found^^!
echo Please extract all files from the downloaded RDP Wrapper package or check your Antivirus.
echo Please extract all files from the downloaded RDP Wrapper package or check your Antivirus.
echo .
echo .
goto : finish
goto : finish
: :
: start_check
: start_check
set rdpwrap_installed = " 0 "
set rdpwrap_installed = " 0 "
REM ----------------------------------
: : ----------------------------------
REM 1) check if TermService is running
: : 1) check if TermService is running
REM ----------------------------------
: : ----------------------------------
sc queryex " TermService " | find " STATE " | find /v " RUNNING " > nul&& (
sc queryex " TermService " | find " STATE " | find /v " RUNNING " > nul&& (
echo [-] TermService NOT running^^!
echo [-] TermService NOT running^^!
call : install
call : install
)||(
)||(
echo [+] TermService running.
echo [+] TermService running.
)
)
REM ------------------------------------------
: : ------------------------------------------
REM 2) check if listener session rdp-tcp exist
: : 2) check if listener session rdp-tcp exist
REM ------------------------------------------
: : ------------------------------------------
set rdp_tcp_session = " "
set rdp_tcp_session = " "
set rdp_tcp_session_id = 0
set rdp_tcp_session_id = 0
if exist %windir% \system32\query.exe (
if exist %windir% \system32\query.exe (
@ -134,9 +138,9 @@ if %rdp_tcp_session_id%==0 (
) else (
) else (
echo [+] Found listener session: %rdp_tcp_session% ^( ID: %rdp_tcp_session_id% ^) .
echo [+] Found listener session: %rdp_tcp_session% ^( ID: %rdp_tcp_session_id% ^) .
)
)
REM -----------------------------------------
: : -----------------------------------------
REM 3) check if rdpwrap.dll exist in registry
: : 3) check if rdpwrap.dll exist in registry
REM -----------------------------------------
: : -----------------------------------------
reg query " HKLM\SYSTEM\CurrentControlSet\Services\TermService\Parameters " /f " rdpwrap.dll " > nul&& (
reg query " HKLM\SYSTEM\CurrentControlSet\Services\TermService\Parameters " /f " rdpwrap.dll " > nul&& (
echo [+] Found windows registry entry for " rdpwrap.dll " .
echo [+] Found windows registry entry for " rdpwrap.dll " .
)||(
)||(
@ -145,9 +149,9 @@ reg query "HKLM\SYSTEM\CurrentControlSet\Services\TermService\Parameters" /f "rd
call : install
call : install
)
)
)
)
REM ------------------------------
: : ------------------------------
REM 4) check if rdpwrap.ini exists
: : 4) check if rdpwrap.ini exists
REM ------------------------------
: : ------------------------------
if exist %rdpwrap_ini% (
if exist %rdpwrap_ini% (
echo [+] Found file: %rdpwrap_ini% .
echo [+] Found file: %rdpwrap_ini% .
) else (
) else (
@ -156,9 +160,9 @@ if exist %rdpwrap_ini% (
call : install
call : install
)
)
)
)
REM ---------------------------------------------------------------
: : ---------------------------------------------------------------
REM 5) get file version of %windir%\System32\termsrv.dll
: : 5) get file version of %windir%\System32\termsrv.dll
REM ---------------------------------------------------------------
: : ---------------------------------------------------------------
for /f " tokens=* usebackq " %% a in (
for /f " tokens=* usebackq " %% a in (
`cscript //nologo " %~f0 ?.wsf " //job:fileVersion " %windir% \System32\termsrv.dll " `
`cscript //nologo " %~f0 ?.wsf " //job:fileVersion " %windir% \System32\termsrv.dll " `
) do (
) do (
@ -170,9 +174,9 @@ if "%termsrv_dll_ver%"=="" (
) else (
) else (
echo [+] Installed " termsrv.dll " version: %termsrv_dll_ver% .
echo [+] Installed " termsrv.dll " version: %termsrv_dll_ver% .
)
)
REM -- ----------------------------------------------------------------------------------------
: : ----------------------------------------------------------------------------------------
REM 6) check if installed file version is different to the last saved file version in registry
: : 6) check if installed fileversion is different to the last saved file version in registry
REM -- ----------------------------------------------------------------------------------------
: : ----------------------------------------------------------------------------------------
echo [*] Read last " termsrv.dll " version from the windows registry...
echo [*] Read last " termsrv.dll " version from the windows registry...
for /f " tokens=2* usebackq " %% a in (
for /f " tokens=2* usebackq " %% a in (
`reg query " HKEY_LOCAL_MACHINE\SOFTWARE\RDP-Wrapper\Autoupdate " /v " termsrv.dll " 2^> nul`
`reg query " HKEY_LOCAL_MACHINE\SOFTWARE\RDP-Wrapper\Autoupdate " /v " termsrv.dll " 2^> nul`
@ -189,9 +193,9 @@ if "%last_termsrv_dll_ver%"=="%termsrv_dll_ver%" (
call : install
call : install
)
)
)
)
REM ---------------------------------------------------------------
: : ---------------------------------------------------------------
REM 7) check if installed termsrv.dll version exists in rdpwrap.ini
: : 7) check if installed termsrv.dll version exists in rdpwrap.ini
REM ---------------------------------------------------------------
: : ---------------------------------------------------------------
: check_update
: check_update
if exist %rdpwrap_ini_check% (
if exist %rdpwrap_ini_check% (
echo [*] Start searching [%termsrv_dll_ver% ] version entry in file %rdpwrap_ini_check% ...
echo [*] Start searching [%termsrv_dll_ver% ] version entry in file %rdpwrap_ini_check% ...
@ -213,10 +217,10 @@ if exist %rdpwrap_ini_check% (
goto : finish
goto : finish
)
)
goto : finish
goto : finish
: :
REM -----------------------------------------------------
: : -----------------------------------------------------
REM Install RDP Wrapper (exactly uninstall and reinstall)
: : Install RDP Wrapper (exactly uninstall and reinstall)
REM -----------------------------------------------------
: : -----------------------------------------------------
: install
: install
echo .
echo .
echo [*] Uninstall and reinstall RDP Wrapper...
echo [*] Uninstall and reinstall RDP Wrapper...
@ -226,10 +230,10 @@ set rdpwrap_installed="1"
%RDPWInst_exe% -i -o
%RDPWInst_exe% -i -o
call : setNLA
call : setNLA
goto : eof
goto : eof
: :
REM -------------------
: : -------------------
REM Restart RDP Wrapper
: : Restart RDP Wrapper
REM -------------------
: : -------------------
: restart
: restart
echo .
echo .
echo [*] Restart RDP Wrapper with new ini (uninstall and reinstall)...
echo [*] Restart RDP Wrapper with new ini (uninstall and reinstall)...
@ -250,10 +254,10 @@ if exist %rdpwrap_new_ini% (
%RDPWInst_exe% -i
%RDPWInst_exe% -i
call : setNLA
call : setNLA
goto : eof
goto : eof
: :
REM --------------------------------------------------------------------
: : --------------------------------------------------------------------
REM Download up-to-date (alternative) version of rdpwrap.ini from GitHub
: : Download up-to-date (alternative) version of rdpwrap.ini from GitHub
REM --------------------------------------------------------------------
: : --------------------------------------------------------------------
: update
: update
echo [*] check network connectivity...
echo [*] check network connectivity...
: netcheck
: netcheck
@ -267,7 +271,7 @@ if errorlevel 1 (
echo [.] Wait for network connection is available...
echo [.] Wait for network connection is available...
ping 127.0.0.1 -n 11> nul
ping 127.0.0.1 -n 11> nul
set /a retry_network_check = retry_network_check + 1
set /a retry_network_check = retry_network_check + 1
REM wait for a maximum of 5 minutes
: : wait for a maximum of 5 minutes
if %retry_network_check% LSS 30 goto netcheck
if %retry_network_check% LSS 30 goto netcheck
: download
: download
set /a github_location = github_location + 1
set /a github_location = github_location + 1
@ -288,21 +292,23 @@ if "%download_status%"=="-1" (
echo [*] Please check you internet connection/firewall and try again^^!
echo [*] Please check you internet connection/firewall and try again^^!
)
)
goto : eof
goto : eof
: :
REM --------------------------------
: : --------------------------------
REM Set Network Level Authentication
: : Set Network Level Authentication
REM --------------------------------
: : --------------------------------
: setNLA
: setNLA
echo [*] Set Network Level Authentication in the windows registry...
echo [*] Set Network Level Authentication in the windows registry...
reg.exe add " HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp " /v SecurityLayer /t reg_dword /d 0x2 /f
reg.exe add " HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp " /v SecurityLayer /t reg_dword /d 0x2 /f
reg.exe add " HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp " /v MinEncryptionLevel /t reg_dword /d 0x2 /f
reg.exe add " HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp " /v MinEncryptionLevel /t reg_dword /d 0x2 /f
goto : eof
goto : eof
: :
: : -------
: : E X I T
: : -------
: finish
: finish
echo .
echo .
exit /b
exit /b
: :
--- Begin wsf script --- fileVersion/fileDownload --->
--- Begin wsf script --- fileVersion/fileDownload --->
< package>
< package>
< job id=" fileVersion " > <script language=" VBScript " >
< job id=" fileVersion " > <script language=" VBScript " >