::Version - 20151104

::https://www.reddit.com/u/MrMeme42

::https://www.reddit.com/r/usefulscripts

@ echo off

::About

::Installer script template. Uses elements of in house startup.bat & installer scripts from PDQ Deploy packs from reddit.com/r/sysadmin

::The aim of the script is to be adapable as possible, using variables so modifications are kept to a minimum for different software

::However check if the paths and commmands are appropriate before using and running

::changelog

::27/10/2015 - Initial Write

::30/10/2015 - Replaced timeout command with ping

:: (timeout doesn't run when used in the background, e.g. used with PDQ deploy)

:: - Added common MSI flags for reference

:: - Added varible for 'All User' app data

::04/11/2015 - Added alternative taskkill command

:: - Added addtional comments

::

:: Converts network path to drive letter

pushd " % ~dp0 "

cls

::

:: Program to install

:: If files are stored in the same directory, the folder path is not required

set LOCATION=

::Name of installer EXE or MSI

set BINARY=

::Installer flags

::Examples:

::Common flags for MSI installers "/quiet /norestart"

set FLAGS=

::exe name & program name

::Needed for variables that remove files or end running processes

set RUNEXE=

set NAME=

::

:: Change into starting directory

cd " % ~dp0 "

cls

::Determine O/S architecture

if exist " % ProgramFiles(x86) % " ( set TYPE=64 ) else ( set TYPE=32 )

::

::Determine which O/S is running

::If using Vista use Win7 commands

ver | find "5.1.26" > nul

if % ERRORLEVEL % == 0 goto winxp

ver | find "6.1.76" > nul

if % ERRORLEVEL % == 0 goto win7

::

:: Create some OS agnostic variables

: win7

set OS=Windows7

@ echo I'm running % OS % , % TYPE % -bit

:: All Users/Public Desktop & Start Menu

set DESKTOP= % PUBLIC % \Desktop

set STARTMENU= % PROGRAMDATA % \Microsoft\Windows\Start Menu\Programs

set ALLUSERSAPP= % ALLUSERSPROFILE %

::

goto start

: winxp

set OS=WindowsXP

@ echo I'm running % OS % , % TYPE % -bit

:: All Users/Public Desktop & Start Menu

set DESKTOP= % ALLUSERSPROFILE % \Desktop

set STARTMENU= % ALLUSERSPROFILE % \Start Menu\Programs

set ALLUSERSAPP= % ALLUSERSPROFILE % \Application Data

::

goto start

::

: start

::

::Kill program if it's running

::%WINDIR%\system32\taskkill.exe /F /fi "IMAGENAME eq %NAME%*" /T

% WINDIR % \system32\taskkill.exe /F /IM % RUNEXE % /T

::Uninstall program before installing new version

wmic product where "name like ' % NAME % __'" uninstall /nointeractive

::Ping is used as a timeout because using 'timeout' doesn't like being run in the background =(

::timeout /t 30

ping 127.0.0.1 -n 30

cls

::Remove any left over files

if % TYPE % ==64 ( for /d %% G in ( " % PROGRAMFILES(X86) % \* % NAME % *" ) do rmdir /s /q " % % ~G" ) else ( for /d %% G in ( " % PROGRAMFILES % \* % NAME % *" ) do rmdir /s /q " % % ~G" )

::

:: Installs the progam with the set installer, and flags

:: (If any addtional files are needed they should be stored in the same directory)

" % BINARY % " % FLAGS %

::

:: Remove Desktop icons

del /q /f " % DESKTOP % \* % NAME % *.lnk"

::

::Stop & Delete unwanted windows services

::net stop "servericename"

::sc delete "servicenamename"

::

::Add addtional commands here if needed

::

::

:: Return to orginal directory

popd

::

:: Return exit code if running from PDQ Deploy