anchor.diff:  :: Purpose:       Installs a package
   :: Requirements:  Run this script with Administrator rights
   :: Author:        vocatus on reddit.com/r/sysadmin ( vocatus.gate@gmail.com ) // PGP key ID: 0x07d1490f82a211a2
  -:: History:       1.0.1 + Add commands to stop and restart TightVNC server service after installation. Thanks to /u/BadMoodinTheMorning
  +:: History:       1.0.2 + Add proper console and logfile logging
  +::                1.0.1 + Add commands to stop and restart TightVNC server service after installation. Thanks to /u/BadMoodinTheMorning
   ::                1.0.0 + Initial write
   
   
  
positive.code: :: VARIABLES :: -- Set these to your desired values
  :::::::::::::::
  :: Log location and name. Do not use trailing slashes (\)
  set LOGPATH=%SystemDrive%\Logs
  set LOGFILE=
  
  :: Package to install. Do not use trailing slashes (\)
  set LOCATION=
  set BINARY=TightVNC v2.8.5 x64.msi
  set FLAGS=/quiet /norestart ADDLOCAL="Server,Viewer"
  
  :: Create the log directory if it doesn't exist
  
negative.code: :: INSTALLATION ::
  ::::::::::::::::::
  :: This line uninstalls any prior version
  echo %CUR_DATE% %TIME% Removing previous versions, please wait...
  echo %CUR_DATE% %TIME% Removing previous versions, please wait...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  "%ProgramFiles%\TightVNC\uninstall.exe" /S >NUL
  "%ProgramFiles(x86)%\TightVNC\uninstall.exe" /S >NUL
  echo %CUR_DATE% %TIME% Done.
  echo %CUR_DATE% %TIME% Done.>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  
  :: Stop any running servers
  echo %CUR_DATE% %TIME% Stopping any running servers...
  echo %CUR_DATE% %TIME% Stopping any running servers...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  "%ProgramFiles%\TightVNC\tvnserver.exe" -stop -silent
  
  :: Delay to let it finish
  ping 127.0.0.1 -n 2
  
  echo %CUR_DATE% %TIME% Done.
  echo %CUR_DATE% %TIME% Done.>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  
  :: Install the new version
  echo %CUR_DATE% %TIME% Installing package...
  echo %CUR_DATE% %TIME% Installing package...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  msiexec.exe /i "%BINARY%" %FLAGS%
  echo %CUR_DATE% %TIME% Done.
  echo %CUR_DATE% %TIME% Done.>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  
  :: Install the new server/listener, and then stops it so we can import the settings file
  echo %CUR_DATE% %TIME% Loading configuration files...
  echo %CUR_DATE% %TIME% Loading configuration files...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  "%ProgramFiles%\TightVNC\tvnserver.exe" -stop -silent
  "%ProgramFiles%\TightVNC\tvnserver.exe" -install -silent
  "%ProgramFiles%\TightVNC\tvnserver.exe" -stop -silent
  
  :: This line imports the new settings
  regedit /s "TightVNC settings.reg"
  echo %CUR_DATE% %TIME% Done.
  echo %CUR_DATE% %TIME% Done.>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  
  :: This line starts the server back up
  echo %CUR_DATE% %TIME% Starting VNC server back up...
  echo %CUR_DATE% %TIME% Starting VNC server back up...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  "%ProgramFiles%\TightVNC\tvnserver.exe" -start -silent >> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  :: Additional step to make sure the service is running
  net stop tvnserver
  net start tvnserver
  
  echo %CUR_DATE% %TIME% Done.
  echo %CUR_DATE% %TIME% Done.>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  
  :::::::::::::
  :: CLEANUP ::
  :::::::::::::
  echo %CUR_DATE% %TIME% Cleaning up...
  echo %CUR_DATE% %TIME% Cleaning up...>> "%LOGPATH%\%LOGFILE%" 2>NUL
  
  :: 64-bit
  if exist "%ProgramFiles%\TightVNC\TightVNC Web Site.url" del "%ProgramFiles%\TightVNC\TightVNC Web Site.url"
  if exist "%ProgramFiles%\TightVNC\LICENSE.txt" del "%ProgramFiles%\TightVNC\LICENSE.txt"
  