I wrote the following script to assist with the deployment of the Citrix Online Plug-In via. Active Directory (or Group Policy). Citrix had stopped providing the client in .MSI format and Administrators had to find a new way to deploy the clients.

This script takes care of one piece of the new deployment. Back when the script was originally written, it’s purpose was to uninstall any Citrix clients found leaving only “Citrix Online Plugin v12.0”, as that was the new targeted version at the time. However, the script has now been updated to remove ANY clients found. There are notes in the script header on how to modify it to leave a targeted version on the machine. Run this script prior to the installation the Citrix client to make sure you have a clean slate before installing the new client.

Update 1 (5/25/2010): * The original version utilized Win32_Product to enumerate the installed products. It sometimes took 4-5 minutes to enumerate. This was not acceptable as this is a logon script that may run every time the computer is started. The script now searches the registry directly in order to speed up processing. This takes about 5 seconds vs. 4-5 minutes.

Update 2 (6/2/2010): * Fixed a bug that would cause the script to blow up if an installed application had anything other than numbers in it’s version.

Update 3 (8/4/2010): * Improved the Uninstall string parsing. The prior versions sometimes got confused on what was the executable and what were the arguments. This was only an issue where the Citrix client was installed using the .EXE. The .MSI uninstalls were fine.

  • Added “Citrix Program Neighborhood” as an install title to be removed as it was overlooked.

  • Added the “Citrix Web ICA Client” to the list of clients to be removed. Unfortunately, CTXSETUP.exe doesn’t have a silent uninstall so users will be prompted if they want to remove. If I get enough requests, I should be able to figure something out using the SendKeys() function.

Update 4 (7/11/2012): * Script is now configured to remove ANY Citrix client found (ie. It is not configured to keep Online Plug-in v12.0 as it once was.)

  • Per request, I added “Citrix Receiver” as an install title to be removed.

Update 5 (10/19/2012): * The script has been updated to work on 64-bit systems.

Update 5 (10/23/2012): * Added CITRIX XENAPP PLUGIN FOR HOSTED APPS as a client to be removed.

'  Title:      Uninstall Old Citrix Clients
'   Date:      5/25/2010
'Updated:      10/23/2012
' Author:      Gregory Strike
'    URL:      http://www.gregorystrike.com/2010/05/24/vbscript-to-uninstall-old-citrix-clients/
'
'Purpose:      The following script will remove any Citrix clients found.  In prior
'              versions it used to leave Citrix Online Plug-in v12.0.  However, 12.0
'              is now out of date.
'
'              To keep a specific client & version around wrap the UninstallApp call
'              in an if statement:
'
'              Example (Would remove any app called 'CITRIX RECEIVER' whose version is less than 13.0):
'              If strName = "CITRIX RECEIVER" Then
'                  If Version < 13.0 Then
'                      UninstallApp strDisplayName, strVersion, strID, strUninstall
'                  End If
'              End If
'
'              This script was originally written as an Active Directory Startup
'              script to assist in deploying the latest Citrix Online Plug-in.
'              It can, however, be ran manually using: CScript.exe [ScriptName.vbs]
'
'Requirements: Administrative Privileges

const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Function UninstallApp(strDisplayName, strVersion, strID, strUninstall)
	Dim objShell
	Dim objFS
	WScript.Echo "Attempting to uninstall: " & strDisplayName & " v" & strVersion

	If strID = "" Then  'We don't know the GUID of the app
		'Look at the Uninstall string and determine what is the
		'executable and what are the command line arguments.
		Set objFS = CreateObject("Scripting.FileSystemObject")

		strExecutable = ""

		'Start from the beginning of the string and see if we can find the excutable in the string
		For X = 0 to Len(strUninstall)
			strExecutableTest = Left(strUninstall, X)
			strExecutableTest = Replace(strExecutableTest, """", "")
			'Test to see if the current string is a file.
			If objFS.FileExists(strExecutableTest) Then
				strExecutable = Trim(strExecutableTest)
				intExecLength = X
			End If
		Next

		If strExecutable = "" Then
			WScript.Echo "Bad string or the executable does not exist: " & strUninstall
			Exit Function
		Else
			strArguments = Right(strUninstall, Len(strUninstall) - intExecLength)
			'WScript.Echo "The executable is: " & strExecutable
			'WScript.Echo "The arguments are: " & strArguments
		End If

		Uninstall = """" & strExecutable & """ " & strArguments 

		If InStr(Uninstall, "ISUNINST.EXE") > 0 Then
			Uninstall = Uninstall & " -a"
		End If
	Else 'We have the GUID
		Uninstall = """MSIEXEC.EXE"" /PASSIVE /X" & strID
	End If

	WScript.Echo "...Executing: " & Uninstall

	Set objShell = WScript.CreateObject("WScript.Shell")
	objShell.Run Uninstall, 1 , 1

	Set objShell = Nothing
End Function

WScript.Echo ""
WScript.Echo Now() & " - Searching for Citrix Clients..."

Set ObjWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

UninstallLoop("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
UninstallLoop("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")

Sub UninstallLoop(strKeyPath)
	ObjWMI.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

	'If strKeyPath doesn't exist, exit the routine before throwing an error.
	If IsNull(arrSubKeys) Then Exit Sub

	WScript.Echo Now() & " - Searching " & strKeyPath

	For Each Product In arrSubKeys
		objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "DisplayName", strDisplayName
		objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "DisplayVersion", strVersion
		objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "UninstallString", strUninstall

		strName = UCase(strDisplayName)

		'Grab the GUID of the MSI if available.
		If Left(Product, 1) = "{" And Right(Product, 1) = "}" Then
			strID = Product
		Else
			strID = ""
		End If

		'Determine version of the Product
		If strVersion <> "" Then
			VersionArray = Split(strVersion, ".")
			If UBound(VersionArray) > 0 Then
				'Verify that only numbers are in the version string
				If IsNumeric(VersionArray(0)) And IsNumeric(VersionArray(1)) Then
					Version = CDbl(VersionArray(0) & "." & VersionArray(1))
				Else
					Version = ""
				End If
			End If
		Else
			Version = ""
		End If

		'Citrix has used many different Client names throughout the years.  This
		'should capture most, if not all, of them.

		If strName = "CITRIX ICA CLIENT" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		If strName = "CITRIX PROGRAM NEIGHBORHOOD" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		If strName = "METAFRAME PRESENTATION SERVER CLIENT" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		If strName = "CITRIX PRESENTATION SERVER CLIENT" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		If strName = "CITRIX ICA WEB CLIENT" Then
			'Unfortunately, CTXSETUP.exe doesn't allow a silent uninstall.
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If	

		If Left(strName, 21) = "CITRIX ONLINE PLUG-IN" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		'Installed with Citrix Receiver
		If Left(strName, 15) = "CITRIX RECEIVER" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		'Installed with Citrix Receiver
		If strName = "ONLINE PLUG-IN" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		'Installed with Citrix Receiver
		If Left(strName, 29) = "CITRIX AUTHENTICATION MANAGER" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		'Installed with Citrix Receiver
		If strName = "SELF-SERVICE PLUG-IN" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If

		If strName = "CITRIX XENAPP PLUGIN FOR HOSTED APPS" Then
			UninstallApp strDisplayName, strVersion, strID, strUninstall
		End If
	Next
End Sub

WScript.Echo Now() & " - Search Complete."
WScript.Echo ""

Gregory Strike

Husband, father, IT dude & blogger wrapped up into one good looking package.