sjlogin

Installer_Template

Oct 27th, 2015
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.23 KB | None | 0 0
  1. ::Version - 20151104
  2. ::https://www.reddit.com/u/MrMeme42
  3. ::https://www.reddit.com/r/usefulscripts
  4. @echo off
  5. ::About
  6. ::Installer script template. Uses elements of in house startup.bat & installer scripts from PDQ Deploy packs from reddit.com/r/sysadmin
  7. ::The aim of the script is to be adapable as possible, using variables so modifications are kept to a minimum for different software
  8. ::However check if the paths and commmands are appropriate before using and running
  9. ::changelog
  10. ::27/10/2015 - Initial Write
  11. ::30/10/2015 - Replaced timeout command with ping
  12. ::      (timeout doesn't run when used in the background, e.g. used with PDQ deploy)             
  13. ::       - Added common MSI flags for reference
  14. ::       - Added varible for 'All User' app data
  15. ::04/11/2015 - Added alternative taskkill command
  16. ::       - Added addtional comments
  17. ::
  18. :: Converts network path to drive letter
  19. pushd "%~dp0"
  20. cls
  21. ::
  22. :: Program to install
  23. :: If files are stored in the same directory, the folder path is not required
  24. set LOCATION=
  25. ::Name of installer EXE or MSI
  26. set BINARY=
  27. ::Installer flags
  28. ::Examples:
  29. ::Common flags for MSI installers "/quiet /norestart"
  30. set FLAGS=
  31. ::exe name & program name
  32. ::Needed for variables that remove files or end running processes
  33. set RUNEXE=
  34. set NAME=
  35. ::
  36. :: Change into starting directory
  37. cd "%~dp0"
  38. cls
  39. ::Determine O/S architecture
  40. if exist "%ProgramFiles(x86)%" (set TYPE=64) else (set TYPE=32)
  41. ::
  42. ::Determine which O/S is running
  43. ::If using Vista use Win7 commands
  44. ver | find "5.1.26" > nul
  45. if %ERRORLEVEL% == 0 goto winxp
  46. ver | find "6.1.76" > nul
  47. if %ERRORLEVEL% == 0 goto win7
  48. ::
  49. :: Create some OS agnostic variables
  50. :win7
  51. set OS=Windows7
  52. @echo I'm running %OS%, %TYPE%-bit
  53. :: All Users/Public Desktop & Start Menu
  54. set DESKTOP=%PUBLIC%\Desktop
  55. set STARTMENU=%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs
  56. set ALLUSERSAPP=%ALLUSERSPROFILE%
  57. ::
  58. goto start
  59. :winxp
  60. set OS=WindowsXP
  61. @echo I'm running %OS%, %TYPE%-bit
  62. :: All Users/Public Desktop & Start Menu
  63. set DESKTOP=%ALLUSERSPROFILE%\Desktop
  64. set STARTMENU=%ALLUSERSPROFILE%\Start Menu\Programs
  65. set ALLUSERSAPP=%ALLUSERSPROFILE%\Application Data
  66. ::
  67. goto start
  68. ::
  69. :start
  70. ::
  71. ::Kill program if it's running
  72. ::%WINDIR%\system32\taskkill.exe /F /fi "IMAGENAME eq %NAME%*" /T
  73. %WINDIR%\system32\taskkill.exe /F /IM %RUNEXE% /T
  74. ::Uninstall program before installing new version
  75. wmic product where "name like '%NAME% __'" uninstall /nointeractive
  76. ::Ping is used as a timeout because using 'timeout' doesn't like being run in the background =(
  77. ::timeout /t 30
  78. ping 127.0.0.1 -n 30
  79. cls
  80. ::Remove any left over files
  81. 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")
  82. ::
  83. :: Installs the progam with the set installer, and flags
  84. :: (If any addtional files are needed they should be stored in the same directory)
  85. "%BINARY%" %FLAGS%
  86. ::
  87. :: Remove Desktop icons
  88. del /q /f "%DESKTOP%\*%NAME%*.lnk"
  89. ::
  90. ::Stop & Delete unwanted windows services
  91. ::net stop "servericename"
  92. ::sc delete "servicenamename"
  93. ::
  94. ::Add addtional commands here if needed
  95. ::
  96.  
  97. ::
  98. :: Return to orginal directory
  99. popd
  100. ::
  101. :: Return exit code if running from PDQ Deploy
  102. exit /B %EXIT_CODE%
Advertisement
Add Comment
Please, Sign In to add comment