Deploying GreenShot screen capture software with SCCM 2012

GreenshotA colleague of mine asked if i could make a handy screen capture tool available to our users. I said ‘Sure – piece of cake!’. Well it was for the most part, aside from the installer loading the website post install.

I will document how i successfully completed the deployment of this software to users who opted to install it via Software Catalog website.

Getting the software

The first thing i tried to do is use the packaged installer they provide (an INNO installer package) however there really was no way to remove the website from loading post install. Instead i decided to use the zip version of the software.

Download the latest ZIP package of the software:http://getgreenshot.org/version-history/

Preparing the package

The source files

Extract the files to your deployment source location. I use the following directory structure:

— \\Server
—- \SoftwareSource
—— \Greenshot
——–\Greenshot1.1.7.17      <— This is where i keep the installation scripts/config file
———-\Greenshot                 <— This is where i extract the source files

The config file

I pre-configure and deploy the file greenshot-fixed.ini so that users can’t override the settings. The settings i put in it are to simply disable automatic updates and to show the Tray icon. Source code is below:

greenshot-fixed.ini

;In this file you should add your fixed settings
; Greenshot core configuration
[Core]
; The language in IETF format (e.g. en-US)
Language=en-US
IsFirstLaunch=False
; Which destinations? Possible options (more might be added by plugins) are: Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail, Picker
ShowTrayNotification=True
; Output file path.
OutputFilePath=
; Use your global proxy?
UseProxy=True
; How many days between every update check? (0=no checks)
UpdateCheckInterval=0
; Last update check
LastUpdateCheck=01/10/2014 12:22:06

The install/uninstall scripts

Below are the installation and un-installation scripts i use to install the software. To update the script for the next available version, you simply update the log file name.

Install_Greenshot.bat

@ECHO OFF
:: ###########################################################
:: # Written by Ivan Dretvic (http://ivan.dretvic.com)
:: # Installs GreenShot 1.1.7.17
:: ###########################################################

::Set log file location.
SET lf="%systemroot%\temp\SCCM_Install_Greenshot_1.1.7.17.log"

ECHO ###%date% - %time% - Install Started > %lf%
ECHO. >> %lf%
ECHO Installing Greenshot software using script >> %lf%
ECHO. >> %lf%

ECHO ###Kill process 'greenshot.exe' and subprocesses forcefully if running >> %lf%
TASKKILL /F /IM Greenshot.exe /T >> %lf%
ECHO. >> %lf%

ECHO ###Make Directory and copy main program files, overwriting existing files >> %lf%
IF EXIST "%ProgramFiles%\Greenshot\greenshot.ini" REN "%ProgramFiles%\Greenshot\greenshot.ini.old%random%"
IF NOT EXIST "%ProgramFiles%\Greenshot" MD "%ProgramFiles%\Greenshot" >> %lf%
xcopy /s /y "%~dp0Greenshot" "%ProgramFiles%\Greenshot\" >> %lf%
ECHO. >> %lf%

ECHO ###Copying configuration ini file/s and overwriting existing file >> %lf%
xcopy /y "%~dp0greenshot*.ini" "%ProgramFiles%\Greenshot\" >> %lf%
ECHO. >> %lf%

ECHO ###NGEN application to improve performance >> %lf%
IF EXIST "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" install "%ProgramFiles%\Greenshot\Greenshot.exe" >> %lf%
IF EXIST "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" install "%ProgramFiles%\Greenshot\GreenshotPlugin.dll" >> %lf%
ECHO. >> %lf%

ECHO ###Installing shortcut to all users start menu >> %lf%
cscript.exe /nologo %~dp0StartupShortcut.vbs "%Programfiles%" >> %lf%
ECHO. >> %lf%

ECHO ### %date% - %time% - Install Finished >> %lf%

StartupShortcut.vbs – The correct way to create a shortcut

'###########################################################
'# Written by Ivan Dretvic (http://ivan.dretvic.com)
'# Creates all users Greenshot start menu short cut
'###########################################################

'This script requires a variable of %ProgramFiles% (or the location of the root folder of Greenshot software).
'This was the simplest method to create appropriate shortcut with minimal code.
On error resume next
if WScript.Arguments.Count > 0 then
	dim shell, lnkPath, link, pfpath
	Set shell = WScript.CreateObject("WScript.shell")
	lnkPath = shell.SpecialFolders("AllUsersStartMenu")
	Set link = shell.CreateShortcut(lnkPath & "\Greenshot.lnk")
	link.Description = "Greenshot - screen capture software"
	pfpath = WScript.Arguments.item(0)
	link.TargetPath = pfpath & "\Greenshot\greenshot.exe"
	link.WorkingDirectory = pfpath & "\Greenshot"
	link.IconLocation = pfpath & "\Greenshot\greenshot.exe,0"
	link.Save
	set shell = nothing
	set lnkpath = nothing
	set link = nothing
	set pfpath = nothing
end if

To Uninstall the software i use the below script
Uninstall_Greenshot.bat

@ECHO OFF
:: ###########################################################
:: # Written by Ivan Dretvic (http://ivan.dretvic.com)
:: # Uninstalls GreenShot 1.1.7.17
:: ###########################################################

::Set log file location.
SET lf="%systemroot%\temp\SCCM_Uninstall_Greenshot_1.1.7.17.log"

ECHO ###%date% - %time% - Uninstall Started > %lf%
ECHO. >> %lf%
ECHO Uninstalling Greenshot software using script >> %lf%
ECHO. >> %lf%

ECHO ###Kill process 'greenshot.exe' and subprocesses forcefully if running >> %lf%
TASKKILL /F /IM Greenshot.exe /T >> %lf%
TASKKILL /F /IM Greenshot.exe /T >> %lf%
ECHO. >> %lf%

ECHO ###Remove main program files directory >> %lf%
IF EXIST "%ProgramFiles%\Greenshot" DEL /F /S /Q "%ProgramFiles%\Greenshot" >> %lf%
IF EXIST "%ProgramFiles%\Greenshot" RD /S /Q "%ProgramFiles%\Greenshot" >> %lf%
ECHO. >> %lf%

ECHO ###NGEN application cache cleaning >> %lf%
IF EXIST "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" uninstall "%ProgramFiles%\Greenshot\Greenshot.exe" >> %lf%
IF EXIST "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" uninstall "%ProgramFiles%\Greenshot\GreenshotPlugin.dll" >> %lf%
ECHO. >> %lf%

ECHO ###Removing shortcut for all users start menu >> %lf%
IF EXIST "%ProgramData%\Microsoft\Windows\Start Menu\Greenshot.lnk" DEL /F /S /Q "%ProgramData%\Microsoft\Windows\Start Menu\Greenshot.lnk" >> %lf%
ECHO. >> %lf%

ECHO ### %date% - %time% - Install Finished >> %lf%

Execution

To install the software, you simply run the Install_greenshot.bat file, with elevated permissions on the client PC. Likewise to uninstall you do the same with the Uninstall script.

Supported deployment methods:

  • SCCM Deployment – I deploy this software as an application to my users as an Available app. They choose to install it via the Software Catalog.
    The Application is configured with the above install and uninstall scripts. The detection method i use (to determine the software is installed) is the version of file %programfiles%\Greenshot\greenshot.exe to be exactly 1.1.7.17.
  • GPO Startup Script – This will work as a startup script installation, however i would modify it by adding two lines to the code. The very first line of the code should say:
    IF EXIST "%ProgramFiles%\Greenshot\Greenshot.exe" GOTO END

    The very last line of the code should say:

    :END

    What this will do is skip the installation every time they boot up, if its already present. If you were updating versions you would remove this line for the new version (or write a clever bit of script to check the file version, or to keep things copy a blank text file for the current version to the program files folder, and simply copy that across with the install. That way if the file is there(greenshot1.1.7.17.txt), then the latest version is installed.

  • Other deployment solution – generally the SCCM method would work, but have not tested it.
  • Manual install – Right click on install, and select Run As Administrator.

Notes

Couple of things i would note about the script:

  • Its a simple script written in BATCH to help others use/modify it easily. Yes it could be neater if written in Powershell but i chose to do it this way for others
  • The script checks that .Net4 is installed, and if so will NGEN the two files. I didnt add any checking to see if .Net2/3/3.5 were installed and find their ngen paths as its a fair amount of code in BATCH so i decided to use the .Net4 which i know all my clients have installed.
  • If you think its great software – then donate to them for their wonderful work. I personally did not want the website to load on my PC’s so i wrote this script. If you dont mind then you can use the INNO setup file.

Resources

  1. Thanks for sharing!

Leave a Reply

QR Code Business Card
%d bloggers like this: