Uninstalling QGIS with SCCM
To make IT sysadmins' lives easier at work (actually, to make my life easier) we use Microsoft's System Centre Configuration Manager (SCCM) to roll out applications to users. We can push out QGIS to machines and the software takes care of 32- or 64-bit architectures and installs the version we want. However, we were having trouble uninstalling older versions of QGIS before installing new versions and this was due to SCCM running the un-installer in the wrong directory and basically nothing happened. After some digging around I found the information required and our tame SCCM and scripting engineer knocked up a simple script that does the necessary.
The Windows registry contains the information required to uninstall an application. For QGIS look in the following keys:
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS Chugiak
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS Brighton
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS Wien
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS Pisa
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS Lyon
The key contains the command to be run to uninstall the software:
“C:/Program Files/QGIS Chugiak/Uninstall-QGIS.exe”
“C:/Program Files/QGIS Brighton/Uninstall-QGIS.exe”
“C:/Program Files/QGIS Wien/Uninstall-QGIS.exe”
“C:/Program Files/QGIS Pisa/Uninstall-QGIS.exe”
“C:/Program Files/QGIS Lyon/Uninstall-QGIS.exe”
This is a script__*__ that works on Windows 7 32- and 64-bit machines and would need to be adjusted to fit your environment. This is for uninstalling QGIS Brighton and a future version could probably check for, and uninstall, multiple versions:
' Run Uninstaller Silently
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run chr(34) & "C:\Program Files\QGIS Brighton\Uninstall-QGIS.exe" & chr(34) & " /S",0,true
Set objShell = Nothing
' Wait 10mins for uninstall to complete
WScript.Sleep(1000 * 60 * 10)
' Delete QGIS Folder
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FolderExists("c:\Program Files\QGIS Brighton") Then
filesys.DeleteFolder "c:\Program Files\QGIS Brighton"
End If
' Delete Desktop Shortcuts
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile("C:\Users\Public\Desktop\OSGeo4W Shell.lnk"), True
If filesys.FileExists("C:\Users\Public\Desktop\OSGeo4W Shell.lnk") Then
filesys.DeleteFile "C:\Users\Public\Desktop\OSGeo4W Shell.lnk"
End If
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile("C:\Users\Public\Desktop\MSYS.lnk"), True
If filesys.FileExists("C:\Users\Public\Desktop\MSYS.lnk") Then
filesys.DeleteFile "C:\Users\Public\Desktop\MSYS.lnk"
End If
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile("C:\Users\Public\SAGA GIS (2.0.8).lnk"), True
If filesys.FileExists("C:\Users\Public\SAGA GIS (2.0.8).lnk") Then
filesys.DeleteFile "C:\Users\Public\SAGA GIS (2.0.8).lnk"
End If
' Wait 10 seconds for deletions to complete
WScript.Sleep 10000
' Create confirmation file on C:
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("C:\QGIS Uninstalled.txt", True)
path = filesys.GetAbsolutePathName("C:\QGIS Uninstalled.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Successfully Uninstalled QGIS.")
filetxt.Close
The script runs the relevant uninstaller silently and waits 10 minutes for it to complete. It then deletes the remaining folder and the desktop shortcuts [Note : currently doesn't uninstall the SAGA shortcut - possibly due to the braces "( )" in the file name?]. It then writes a confirmation file to the root of the C:\ drive.
What this means for us now is that we can search for all machines on the network with older versions of QGIS, uninstall everything and install the version we want everyone to use. Is that a time saver or what?
* Script comes as is and without any warranty what so ever. Use at your own risk. Take precautions.