@ -7,7 +7,7 @@ REM -------------------------------------------------------------------
REM
REM
REM autoupdate.bat
REM autoupdate.bat
REM
REM
REM Automatic RDP Wrapper installer and updater // asmtron (1 3 -08-2019)
REM Automatic RDP Wrapper installer and updater // asmtron (1 4 -08-2019)
REM -------------------------------------------------------------------
REM -------------------------------------------------------------------
REM Options:
REM Options:
REM -log = redirect display output to the file autoupdate.log
REM -log = redirect display output to the file autoupdate.log
@ -40,7 +40,6 @@ 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
echo ___________________________________________
echo ___________________________________________
echo Automatic RDP Wrapper installer and updater
echo Automatic RDP Wrapper installer and updater
echo .
echo .
@ -51,40 +50,40 @@ fsutil dirty query %systemdrive% >nul
if not %errorlevel% == 0 goto : not_admin
if not %errorlevel% == 0 goto : not_admin
REM check for arguments
REM 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%
goto : finish
goto : finish
)
)
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
goto : finish
goto : finish
)
)
if /i " %~1 " == " -taskremove " (
if /i " %~1 " == " -taskremove " (
echo [-] remove autorun of %autoupdate_bat% on startup in the schedule task
echo [-] remove autorun of %autoupdate_bat% on startup in the schedule task^^!
schtasks /delete /f /tn " RDP Wrapper Autoupdate "
schtasks /delete /f /tn " RDP Wrapper Autoupdate "
goto : finish
goto : finish
)
)
if /i not " %~1 " == " " (
if /i not " %~1 " == " " (
echo [x] Unknown argument specified: " %~1 "
echo [x] Unknown argument specified: " %~1 "
echo [*] Supported argments/options are:
echo [*] Supported argments/options are:
echo -log = redirect display output to the file autoupdate.log
echo -log = redirect display output to the file autoupdate.log
echo -taskadd = add autorun of autoupdate.bat on startup in the schedule task
echo -taskadd = add autorun of autoupdate.bat on startup in the schedule task
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
REM 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
echo [-] This script must be run as administrator to work properly!
echo [-] This script must be run as administrator to work properly^^ !
echo ^< Please use 'right click' on this batch file and select " Run As Administrator " ^>
echo ^< Please use 'right click' on this batch file and select " Run As Administrator " ^>
echo .
echo .
goto : finish
goto : finish
: error_install
: error_install
echo [-] RDP Wrapper installer executable (RDPWInst.exe) not found!
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
@ -94,60 +93,76 @@ REM ----------------------------------
REM 1) check if TermService is running
REM 1) check if TermService is running
REM ----------------------------------
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
REM ------------------------------------------
set rdp_tcp_session = " "
for /f " tokens=1-2* usebackq " %% a in (
`query session rdp-tcp`
) do (
set rdp_tcp_session = %% a
set rdp_tcp_session_id = %% b
)
if %rdp_tcp_session% == " " (
echo [-] Listener session rdp-tcp NOT found^^!
call : install
) else (
echo [+] Found listener session: %rdp_tcp_session% ^( ID: %rdp_tcp_session_id% ^) .
)
REM -----------------------------------------
REM -----------------------------------------
REM 2) check if rdpwrap.dll exist in registry
REM 3 ) check if rdpwrap.dll exist in registry
REM -----------------------------------------
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 " .
)||(
)||(
echo [-] NOT found windows registry entry for " rdpwrap.dll " !
echo [-] NOT found windows registry entry for " rdpwrap.dll " ^^ !
if %rdpwrap_installed% == " 0 " (
if %rdpwrap_installed% == " 0 " (
call : install
call : install
)
)
)
)
REM ------------------------------
REM ------------------------------
REM 3) check if rdpwrap.ini exists
REM 4 ) check if rdpwrap.ini exists
REM ------------------------------
REM ------------------------------
if exist %rdpwrap_ini% (
if exist %rdpwrap_ini% (
echo [+] Found file: %rdpwrap_ini%
echo [+] Found file: %rdpwrap_ini% .
) else (
) else (
echo [-] File NOT found: %rdpwrap_ini% !
echo [-] File NOT found: %rdpwrap_ini% ^^ !
if %rdpwrap_installed% == " 0 " (
if %rdpwrap_installed% == " 0 " (
call : install
call : install
)
)
)
)
REM ---------------------------------------------------------------
REM ---------------------------------------------------------------
REM 4 ) get file version of %windir%\System32\termsrv.dll
REM 5 ) get file version of %windir%\System32\termsrv.dll
REM ---------------------------------------------------------------
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 (
set termsrv_dll_ver = %% a
set termsrv_dll_ver = %% a
)
)
if " %termsrv_dll_ver% " == " " (
if " %termsrv_dll_ver% " == " " (
echo [x] Error on getting the file version of %windir% \System32\termsrv.dll
echo [x] Error on getting the file version of " %windir% \System32\termsrv.dll" ^^!
goto : finish
goto : finish
) else (
) else (
echo [+] Installed " termsrv.dll " version: %termsrv_dll_ver%
echo [+] Installed " termsrv.dll " version: %termsrv_dll_ver% .
)
)
REM ----------------------------------------------------------------------------------------
REM ----------------------------------------------------------------------------------------
REM 5 ) check if installed fileversion is different to the last saved fileversion in registry
REM 6 ) check if installed fileversion is different to the last saved fileversion in registry
REM ----------------------------------------------------------------------------------------
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* " %% 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`
) do (
) do (
set last_termsrv_dll_ver = %% b
set last_termsrv_dll_ver = %% b
)
)
if " %last_termsrv_dll_ver% " == " %termsrv_dll_ver% " (
if " %last_termsrv_dll_ver% " == " %termsrv_dll_ver% " (
echo [+] Current " termsrv.dll v. %termsrv_dll_ver% " same as last " termsrv.dll v. %last_termsrv_dll_ver% "
echo [+] Current " termsrv.dll v. %termsrv_dll_ver% " same as last " termsrv.dll v. %last_termsrv_dll_ver% " .
) else (
) else (
echo [-] Current " termsrv.dll v. %termsrv_dll_ver% " different from last " termsrv.dll v. %last_termsrv_dll_ver% " !
echo [-] Current " termsrv.dll v. %termsrv_dll_ver% " different from last " termsrv.dll v. %last_termsrv_dll_ver% " ^^ !
echo [*] Update current " termsrv.dll " version to the windows registry...
echo [*] Update current " termsrv.dll " version to the windows registry...
reg add " HKEY_LOCAL_MACHINE\SOFTWARE\RDP-Wrapper\Autoupdate " /v " termsrv.dll " /t REG_SZ /d " %termsrv_dll_ver% " /f
reg add " HKEY_LOCAL_MACHINE\SOFTWARE\RDP-Wrapper\Autoupdate " /v " termsrv.dll " /t REG_SZ /d " %termsrv_dll_ver% " /f
if %rdpwrap_installed% == " 0 " (
if %rdpwrap_installed% == " 0 " (
@ -155,26 +170,26 @@ if "%last_termsrv_dll_ver%"=="%termsrv_dll_ver%" (
)
)
)
)
REM ---------------------------------------------------------------
REM ---------------------------------------------------------------
REM 6 ) check if installed termsrv.dll version exists in rdpwrap.ini
REM 7 ) check if installed termsrv.dll version exists in rdpwrap.ini
REM ---------------------------------------------------------------
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% ...
findstr /c:" [ %termsrv_dll_ver% ] " %rdpwrap_ini_check% > nul&& (
findstr /c:" [ %termsrv_dll_ver% ] " %rdpwrap_ini_check% > nul&& (
echo [+] Found " termsrv.dll " version entry [%termsrv_dll_ver% ] in file %rdpwrap_ini_check%
echo [+] Found " termsrv.dll " version entry [%termsrv_dll_ver% ] in file %rdpwrap_ini_check% .
echo [*] RDP- Wrapper seems to be up-to-date and working...
echo [*] RDP Wrapper seems to be up-to-date and working...
)||(
)||(
echo [-] NOT found " termsrv.dll " version entry [%termsrv_dll_ver% ] in file %rdpwrap_ini_check% !
echo [-] NOT found " termsrv.dll " version entry [%termsrv_dll_ver% ] in file %rdpwrap_ini_check% ^^ !
if not " !rdpwrap_ini_update_github_%github_location%! " == " " (
if not " !rdpwrap_ini_update_github_%github_location%! " == " " (
set rdpwrap_ini_url = !rdpwrap_ini_update_github_%github_location%!
set rdpwrap_ini_url = !rdpwrap_ini_update_github_%github_location%!
call : update
call : update
goto : check_update
goto : check_update
)
)
goto : finish
goto : finish
)
)
) else (
) else (
echo [-] File NOT found: %rdpwrap_ini_check%
echo [-] File NOT found: %rdpwrap_ini_check% .
echo [*] Give up - Please check if Antivirus/Firewall blocks the file %rdpwrap_ini_check% !
echo [*] Give up - Please check if Antivirus/Firewall blocks the file %rdpwrap_ini_check% ^^ !
goto : finish
goto : finish
)
)
goto : finish
goto : finish
@ -184,7 +199,7 @@ REM Install RDP Wrapper (exactly uninstall and reinstall)
REM -----------------------------------------------------
REM -----------------------------------------------------
: install
: install
echo .
echo .
echo [*] Uninstall and reinstall RDP Wrapper ...
echo [*] Uninstall and reinstall RDP Wrapper...
echo .
echo .
set rdpwrap_installed = " 1 "
set rdpwrap_installed = " 1 "
%RDPWInst_exe% -u
%RDPWInst_exe% -u
@ -192,18 +207,41 @@ set rdpwrap_installed="1"
goto : eof
goto : eof
REM -------------------
REM -------------------
REM Restart RDP - Wrapper
REM Restart RDP Wrapper
REM -------------------
REM -------------------
: restart
: restart
if %rdpwrap_installed% == " 0 " (
if %rdpwrap_installed% == " 0 " (
call : install
call : install
)
)
REM NOTE normal copy of the file "rdpwrap_new.ini" to "rdpwrap.ini" will not work (file locked)
REM we need to stream the data line by line from "rdpwrap_new.ini" to "rdpwrap.ini"
if exist %rdpwrap_new_ini% (
if exist %rdpwrap_new_ini% (
echo [*] Start copy %rdpwrap_new_ini% to %rdpwrap_ini% ...
echo [*] Start streaming %rdpwrap_new_ini% to %rdpwrap_ini% ...
copy /y %rdpwrap_new_ini% %rdpwrap_ini%
set firstline = " 0 "
for /f " usebackq delims= " %% a in (
`findstr /n " ^ " %rdpwrap_new_ini% `
) do (
set " line=! %% a! "
set " line=!line:*:=! "
if !firstline! == " 0 " (
set firstline = " 1 "
if " !line! " == " *:= " (
echo .> %rdpwrap_ini%
) else (
echo !line! > %rdpwrap_ini%
)
) else (
if " !line! " == " *:= " (
echo .>> %rdpwrap_ini%
) else (
echo !line! >> %rdpwrap_ini%
)
)
)
echo [+] Update of %rdpwrap_ini% finished successfully.
)
)
echo .
echo .
echo [*] Restart RDP Wrapper ...
echo [*] Restart RDP Wrapper...
echo .
echo .
%RDPWInst_exe% -r
%RDPWInst_exe% -r
goto : eof
goto : eof
@ -214,7 +252,7 @@ REM --------------------------------------------------------------------
: update
: update
set /a github_location = github_location + 1
set /a github_location = github_location + 1
echo .
echo .
echo [*] Download latest version of rdpwrap.ini from GitHub
echo [*] Download latest version of rdpwrap.ini from GitHub...
echo -^> %rdpwrap_ini_url%
echo -^> %rdpwrap_ini_url%
for /f " tokens=* usebackq " %% a in (
for /f " tokens=* usebackq " %% a in (
`cscript //nologo " %~f0 ?.wsf " //job:fileDownload %rdpwrap_ini_url% %rdpwrap_new_ini% `
`cscript //nologo " %~f0 ?.wsf " //job:fileDownload %rdpwrap_ini_url% %rdpwrap_new_ini% `
@ -222,12 +260,12 @@ for /f "tokens=* usebackq" %%a in (
set " download_status= %% a "
set " download_status= %% a "
)
)
if " %download_status% " == " -1 " (
if " %download_status% " == " -1 " (
echo [+] Successfully download from GitHhub latest version to %rdpwrap_new_ini%
echo [+] Successfully download from GitHhub latest version to %rdpwrap_new_ini% .
set rdpwrap_ini_check = %rdpwrap_new_ini%
set rdpwrap_ini_check = %rdpwrap_new_ini%
call : restart
call : restart
) else (
) else (
echo [-] FAILED to download from GitHub latest version to %rdpwrap_new_ini%
echo [-] FAILED to download from GitHub latest version to %rdpwrap_new_ini% ^^!
echo [*] Please check you internet connection/firewall and try again!
echo [*] Please check you internet connection/firewall and try again^^ !
)
)
goto : eof
goto : eof