WSF: Update Published Application Icons 1.0
This script will update the icon of each published application in your Citrix Presentation Server farm. The code listed here will cylce through each application and update the icon from the executable listed command line property.
The script must be run on a server running Presentation Server, please don’t attempt to run this script from a remote machine. You may have to customise the code to suit your environment.
<package>
<job id="Update Icons" prompt="no">
<?job error="false" debug="false" ?>
<runtime>
<description>
</description>
</runtime>
<reference object="MetaFrameCOM.MetaFrameFarm"/>
<script id="UpdateIcons" language="VBScript">
Option Explicit
Dim oMFCOM, aArray, n, sErr
Set oMFCOM = New MFCOM45
oMFCOM.Enabled = True
If oMFCOM.InitialiseFarm Then
If oMFCOM.IsAdministrator Then
aArray = oMFCOM.GetApplicationsList
For n = 0 To UBound(aArray)
WScript.Echo "Checking: " & aArray(n)
oMFCOM.UpdateApplicationIcon(aArray(n))
WScript.Echo
Next
End If
End If
Class MFCOM45
Private oMetaFrameFarm
Private bEnabled, sServerName
Public Property Get Enabled
Enabled = bEnabled
End Property
Public Property Let Enabled(bValue)
bEnabled = bValue
End Property
Public Property Get Server
Server = sServerName
End Property
Public Property Let Server(bValue)
sServerName = bValue
End Property
Public Function InitialiseFarm
If bEnabled Then
On Error Resume Next
Err.Clear
If VarType(sServerName) <> vbString Then
Set oMetaFrameFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
oMetaFrameFarm.Initialize(MetaFrameWinFarmObject)
Else
Set oMetaFrameFarm = CreateObject("MetaFrameCOM.MetaFrameFarm", sServerName)
oMetaFrameFarm.Initialize(MetaFrameWinFarmObject)
End If
If Err.Number <> 0 Then
InitialiseFarm = Err.Number
Exit Function
Else
InitialiseFarm = True
End If
End If
End Function
Public Function IsAdministrator
If bEnabled Then
If oMetaFrameFarm.WinFarmObject.IsCitrixAdministrator = 0 Then
IsAdministrator = False
Else
IsAdministrator = True
End If
End If
End Function
Public Function GetApplicationsList
If bEnabled Then
Dim aAppList(), iApp, Application
iApp = 0
For Each Application In oMetaFrameFarm.Applications
Application.LoadData(TRUE)
ReDim Preserve aAppList(iApp)
aAppList(iApp) = Application.DistinguishedName
iApp = iApp + 1
Next
GetApplicationsList = aAppList
Set iApp = Nothing
End If
End Function
Public Function UpdateApplicationIcon(ByVal sApplicationDN)
If bEnabled Then
Dim oFileSys, oCommandLine, aArray, Application, oApplication, sExec
Set oFileSys = CreateObject("Scripting.FileSystemObject")
Set oApplication = CreateObject("MetaFrameCOM.MetaFrameApplication")
oApplication.Initialize MetaFrameWinAppObject, sApplicationDN
oApplication.LoadData(1)
If InStr(oApplication.WinAppObject.DefaultInitProg, Chr(34)) Then
aArray = Split(oApplication.WinAppObject.DefaultInitProg, Chr(34))
sExec = aArray(1)
ElseIf InStr(oApplication.WinAppObject.DefaultInitProg, Chr(32)) Then
aArray = Split(oApplication.WinAppObject.DefaultInitProg, Chr(32))
sExec = aArray(0)
Else
sExec = Replace(oApplication.WinAppObject.DefaultInitProg, Chr(34), "")
End If
If oFileSys.FileExists(sExec) Then
WScript.Echo "Updating icon."
oApplication.WinAppObject.ReadIconFromFile sExec, 0
oApplication.Validate()
If Err.Number <> 0 Then
UpdateApplicationIcon = Err.Number
Else
On Error Resume Next
oApplication.SaveData()
UpdateApplicationIcon = Err.Number
End If
Else
WScript.Echo "Cannot find executable to update icon."
End If
Set oApplication = Nothing
Set oFileSys = Nothing
End If
End Function
End Class
</script>
</job>
</package>
