CitrixTools.Net Articles

Current Articles | Categories | Search | Syndication

Sample scripts to Uninstall Citrix Clients

During migrations you may have had to upgrade the XenApp client to its latest version.

To do so, it is often better to uninstall the previous clients before installing the new one.

To automate this task I've written two little scripts that are shared through this article.

Be careful when using them and be sure to test them before releasing them to production.

As always this content is provided as is and using it is at your own risks.

This first script has been designed to remove a specific product. To do so it is relying on the product name. In this example, the provided name is "Citrix Presentation Server Client".

If you want to uninstall another client version, then change the name constant to the one needed.

'-------------------------------------------------------------------------------------

On Error Resume Next
Const strComputer = "."
Const strLogFile = "c:\UninstallLog.txt"
Const strClientName = "Citrix Presentation Server Client"
Const ForAppending = 8
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
    If objFSO.FileExists(strLogFile) = False Then
        Set objTextFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)
        Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where Name = '" & strClientName & "'")
        For Each objSoftware in colSoftware
            On Error Resume Next
            Err.Clear
            objTextFile.WriteLine(WshNetwork.ComputerName & Space(1) & ":" & Space(1) & "Uninstalling" & Space(1) & objSoftware.Name & Space(1) & "from" & Space(1) & objSoftware.Vendor)
            objSoftware.Uninstall()
            If Err then
                objTextFile.WriteLine("Error : " & Err.Number & " => " & Err.Description)
            End If
        Next
    End If

'-------------------------------------------------------------------------------------

This second script is more rough.

Actually it'll parse all installed programs and uninstall all programs written by "Citrix" in our case (actually all programs where vendor name contains "Citrix"), so it has to be used more carefully but is really useful when trying to uninstall lots of different versions without knowing all clients names.

'-------------------------------------------------------------------------------------

On Error Resume Next
Const strComputer = "."
Const strLogFile = "c:\UninstallLog.txt"
Const strVendorName = "Citrix"
Const ForAppending = 8
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
    If objFSO.FileExists(strLogFile) = False Then
        Set objTextFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)
        Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where Name = '" & strClientName & "'")
        For Each objSoftware in colSoftware
            On Error Resume Next
            Err.Clear
           If Instr(Ucase(objSoftware.Vendor),UCase(strVendorName)) > 0 then
                objTextFile.WriteLine(WshNetwork.ComputerName & Space(1) & ":" & Space(1) & "Uninstalling" & Space(1) & objSoftware.Name & Space(1) & "from" & Space(1) & objSoftware.Vendor)
                objSoftware.Uninstall()
                If
Err then
                    objTextFile.WriteLine("Error : " & Err.Number & " => " & Err.Description)
                End If
            End if
        Next
    End If

'-------------------------------------------------------------------------------------

posted on Monday, August 17, 2009 11:29 PM by Pierre Marmignon    

Previous Page | Next Page

COMMENTS

Only registered users may post comments.