XenApp: Automated application publishing using PowerShell


To publish Notepad.exe in XenApp automatically using PowerShell script.


Following are the prerequisites for setting up the environment to execute PowerShell script to publish application in XenApp:

  1. .Net Framework 3.5 SP1 {Download it from Microsoft website}
  2. Microsoft PowerShell 1.0 {Download it from Microsoft website}
  3. XenApp Command technology preview{Download it from citrix site: https://www.citrix.com/English/ss/downloads/details.asp?downloadId=1687620&productId=186#top} : These commands are a PowerShell Tool Pack that allows managing most aspects related to XenApp.  They cover all of MFCOM functionality for features available in XenApp 5 and include functionality from both AMC and CMC.

Install all the above components in the given order onto the XenApp environment.


Below script is the solution. It has five parts:

  • Creation of input box for application information – {Line 10 – 123}
  • Creation of new folder under Applications folder {Applications/Test} – {Line 125}
  • Creation the published application for Notepad – {Line 127-138}
  • Addition of users/groups to the application –{Line 140-141}
  • Assignment of servers to the published app –{Line 143-144}


       1: # ===============================================================

       2: # 

       3: # AUTHOR: Mohd Aslam

       4: # DATE  : 6/22/2010

       5: # 

       6: # COMMENT: This script publishes notepad in XenApp

       7: # 

       8: # ===============================================================


      10: [void] [System.Reflection.Assembly]::LoadWithPartialName(

      11: "System.Drawing") 

      12: [void] [System.Reflection.Assembly]::LoadWithPartialName(

      13: "System.Windows.Forms") 


      15: $objForm = New-Object System.Windows.Forms.Form 

      16: $objForm.Text = "Application publish information"

      17: $objForm.Size = New-Object System.Drawing.Size(430,250) 

      18: $objForm.StartPosition = "CenterScreen"


      20: $objForm.KeyPreview = $True

      21: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 

      22:     {$x=$objTextBox.Text;$objForm.Close()}})

      23: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 

      24:     {$objForm.Close()}})


      26: $OKButton = New-Object System.Windows.Forms.Button

      27: $OKButton.Location = New-Object System.Drawing.Size(190,190)

      28: $OKButton.Size = New-Object System.Drawing.Size(75,23)

      29: $OKButton.Text = "OK"

      30: $OKButton.Add_Click(

      31: {

      32: $AppName=$objAppName.Text;

      33: $AppLoc=$objAppLoc.Text;

      34: $AppWD=$objAppWD.Text;

      35: $AppUsers=$objAppUsers.Text;

      36: $AppServers=$objAppServers.Text;

      37: $objForm.Close()

      38: }

      39: )

      40: $objForm.Controls.Add($OKButton)


      42: $CancelButton = New-Object System.Windows.Forms.Button

      43: $CancelButton.Location = New-Object System.Drawing.Size(290,190)

      44: $CancelButton.Size = New-Object System.Drawing.Size(75,23)

      45: $CancelButton.Text = "Cancel"

      46: $CancelButton.Add_Click(

      47: {

      48: $objForm.Close()

      49: }

      50: )

      51: $objForm.Controls.Add($CancelButton)


      53: $objLabel = New-Object System.Windows.Forms.Label

      54: $objLabel.Location = New-Object System.Drawing.Size(10,20) 

      55: $objLabel.Size = New-Object System.Drawing.Size(280,20) 

      56: $objLabel.Text = "Please enter the information in the space below:"

      57: $objForm.Controls.Add($objLabel) 


      59: $objLbl_AppName = New-Object System.Windows.Forms.Label

      60: $objLbl_AppName.Location = New-Object System.Drawing.Size(10,40) 

      61: $objLbl_AppName.Size = New-Object System.Drawing.Size(160,20) 

      62: $objLbl_AppName.Text = "Application Name:"

      63: $objForm.Controls.Add($objLbl_AppName) 


      65: $objAppName = New-Object System.Windows.Forms.TextBox 

      66: $objAppName.Location = New-Object System.Drawing.Size(190,40) 

      67: $objAppName.Size = New-Object System.Drawing.Size(205,20) 

      68: $objForm.Controls.Add($objAppName) 


      70: $objLbl_AppLoc = New-Object System.Windows.Forms.Label

      71: $objLbl_AppLoc.Location = New-Object System.Drawing.Size(10,70) 

      72: $objLbl_AppLoc.Size = New-Object System.Drawing.Size(160,20) 

      73: $objLbl_AppLoc.Text = "Application Command Line:"

      74: $objForm.Controls.Add($objLbl_AppLoc) 


      76: $objAppLoc = New-Object System.Windows.Forms.TextBox 

      77: $objAppLoc.Location = New-Object System.Drawing.Size(190,70) 

      78: $objAppLoc.Size = New-Object System.Drawing.Size(205,20) 

      79: $objForm.Controls.Add($objAppLoc) 


      81: $objLbl_AppWD = New-Object System.Windows.Forms.Label

      82: $objLbl_AppWD.Location = New-Object System.Drawing.Size(10,100) 

      83: $objLbl_AppWD.Size = New-Object System.Drawing.Size(160,20) 

      84: $objLbl_AppWD.Text = "Working Directory:"

      85: $objForm.Controls.Add($objLbl_AppWD) 


      87: $objAppWD = New-Object System.Windows.Forms.TextBox 

      88: $objAppWD.Location = New-Object System.Drawing.Size(190,100) 

      89: $objAppWD.Size = New-Object System.Drawing.Size(205,20) 

      90: $objForm.Controls.Add($objAppWD) 


      92: $objLbl_AppUsers = New-Object System.Windows.Forms.Label

      93: $objLbl_AppUsers.Location = New-Object System.Drawing.Size(10,130) 

      94: $objLbl_AppUsers.Size = New-Object System.Drawing.Size(160,20) 

      95: $objLbl_AppUsers.Text = "Application Users*:"

      96: $objForm.Controls.Add($objLbl_AppUsers) 


      98: $objAppUsers = New-Object System.Windows.Forms.TextBox 

      99: $objAppUsers.Location = New-Object System.Drawing.Size(190,130) 

     100: $objAppUsers.Size = New-Object System.Drawing.Size(205,20) 

     101: $objForm.Controls.Add($objAppUsers) 


     103: $objLbl_Server = New-Object System.Windows.Forms.Label

     104: $objLbl_Server.Location = New-Object System.Drawing.Size(10,160) 

     105: $objLbl_Server.Size = New-Object System.Drawing.Size(160,20) 

     106: $objLbl_Server.Text = "Servers*:"

     107: $objForm.Controls.Add($objLbl_Server) 


     109: $objAppServers = New-Object System.Windows.Forms.TextBox 

     110: $objAppServers.Location = New-Object System.Drawing.Size(190,160) 

     111: $objAppServers.Size = New-Object System.Drawing.Size(205,20) 

     112: $objForm.Controls.Add($objAppServers) 


     114: $objLbl_Server = New-Object System.Windows.Forms.Label

     115: $objLbl_Server.Location = New-Object System.Drawing.Size(10,200) 

     116: $objLbl_Server.Size = New-Object System.Drawing.Size(180,20) 

     117: $objLbl_Server.Text = "*: Enter ';' separated data if any"

     118: $objForm.Controls.Add($objLbl_Server) 


     120: $objForm.Topmost = $True


     122: $objForm.Add_Shown({$objForm.Activate()})

     123: [void] $objForm.ShowDialog()


     125: New-XAFolder Applications/Test


     127: New-XAApplication -BrowserName $AppName `

     128: -ApplicationType "ServerInstalled" `

     129: -DisplayName $AppName -FolderPath "Applications/Test" `

     130: -Enabled $true `

     131: -CommandLineExecutable $AppLoc `

     132: -WorkingDirectory $AppWD `

     133: -AnonymousConnectionsAllowed $false `

     134: -AddToClientStartMenu $false `

     135: -InstanceLimit "-1" `

     136: -ColorDepth 1 `

     137: -AudioRequired $false `

     138: -ClientFolder "Test"`


     140: Add-XAApplicationAccount -BrowserName $AppName `

     141: -Accounts $AppUsers.Split(";")


     143: Add-XAApplicationServer -BrowserName $AppName `

     144: -ServerNames $AppServers.Split(";")

     How to Run above script?:

    Save above script to some location with .ps1 extension. To Run above script, go to “Programs > Citrix > XenApp Commands” and click “Windows PowerShell with XenApp Commands (CTP2)” icon. It will launch PowerShell command prompt.

    On the PowerShell command prompt, write script name with full location and click enter. Script will run and below screen will be displayed:


    Enter all the required data and click “Ok”. For application users and servers, multiple data can be entered separated by “;”.

    Following screen will be displayed containing information about the published icon.


    To confirm the successful publish, go to access management console and see the published icon as:



  • Advertisements

    XenApp: VBScript to write to users registry

    Some applications have requirement that they expects/read some values/data from current users hive in registry and this data usually get added to the users registry during application installation. Now in XenApp, since the application will be installed on the single XenApp server so the data will be added to current user hive in registry for the administrator who will install it. Now when such application will be published for users and when users will try to run this application, this application might break or might not behave properly as it will try to read some data from the current users hive which is not present for that particular user.

    To implement this requirement in XenApp, we have to write VBScript to write data into the current user registry hive.

    Let me describe problem statement:

    Problem statement:

    1. User’s do not have rights to use “regedit” command. The only allowed way for user’s to write to their registry is by using RegWrite command.
    2. We need to write some value say “VALUE” to the key “Folder” at current user hive “HKEY_CURRENT_USER\Software\XYZ\ABC\11.1”
    3. We need to write “123456” to the key “aaa/bbb” at the current user hive “HKEY_CURRENT_USER\Software\XYZ\ABC”. Please note the forward slash in-between the key.
    4. Once above steps will be implemented, application should be launched.

    Solution: Below VBScript is the solution. Let us discuss the solution of above four problems.

    For first problem, where users are restricted rights, we have created function “WriteReg” which is taking key, value and type as input and executing RegWrite command to write the value into the registry.

    For second problem, we are calling “WriteReg” function with the required parameters.

    For third problem, we have to pass key with the format “\\\aaa/bbb”.

    For forth problem, we have used notepad as an example.



    ' NAME: RegistryEdit.vbs


    ' AUTHOR: Mohd Aslam

    ' DATE  : 06/18/2010


    ' COMMENT: 

    ' This script edits registry



    Dim objFSO, WshShell


    Set WshShell = WScript.CreateObject("WScript.Shell")

    set objFSO = CreateObject("Scripting.FileSystemObject")


    WriteReg "HKEY_CURRENT_USER\Software\XYZ\ABC\11.1\Folder", "VALUE", "REG_SZ"

    WriteReg "HKEY_CURRENT_USER\Software\XYZ\ABC\\\aaa/bbb", "123456", "REG_SZ"


    Sub WriteReg(strKey, strValue, strType)

    WshShell.RegWrite strKey, strValue, strType   

    End Sub


    'Execute the Noteoad program

    WshShell.Run "c:\WINDOWS\notepad.exe"


    If Err.Number<>0 Then    

    MsgBox "Unable to launch Notepad program!"

    MsgBox "Error #" & Err.Number & " " & Err.Source & " " & Err.Description

    End If


    set WshShell = Nothing

    Now in XenApp, we just need to publish this VBScript.

    It can be published in XenApp as shown below:

    Note: For more information on publishing in XenApp, refer to my article https://mdaslam.wordpress.com/2010/06/10/application-publish-in-xenapp/


    XenApp: VBScript to Map Network drives

    Some applications have requirement that they need some mapped location either at the beginning or at any time in between their execution. They will not behave properly in the absence of the mapped locations. Sometimes they need it to get some files/data or to save some file/data onto that location.

    To implement this requirement in XenApp, we have write VBScript to map the network location to some drive and then we have to publish it in XenApp.

    Note:The drive which is going to be used for mapping purpose should not be used by other application or should not be reserved one like V drive {mapped to C drive of XenApp}, X drive {roaming profile drive}, C drive, D drive {may be CD drive}. If used/non reserved drives are used, then it might brake other application using those drives. if the reserved drives are used in VBScript, then mapping will not happen.


    Users should have required access rights {atleast “read” access} on to the network location.

    Below is the content of VBScript:

    1. We are checking, if H drive is already mapped
    2. If it is already in use i.e. mapped, we have removed its mapping.
    3. Finally, we are mapping H drive to the required network location “\\Server\Share”.
    4. Launching the Notepad application.

    ' NAME: NetworkMap.vbs


    ' AUTHOR: Mohd Aslam

    ' DATE  : 06/09/2010


    ' COMMENT: 

    ' This script maps H drive to "\\Server\Share" and then launch Notepad exe


    Dim objFSO, objNetwork, WshShell


    Set WshShell = WScript.CreateObject("WScript.Shell")

    set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objNetwork = CreateObject("WScript.Network")



    'If the "H" drive is already mapped, disconnect the mapping


    If (objFSO.DriveExists("H:")) Then

    objNetwork.RemoveNetworkDrive "H:", True, True

    End If


    objNetwork.MapNetworkDrive "H:" , "\\Server\Share"


    If Err.Number<>0 Then    

    MsgBox "Error in mapping drive!!!!"

    MsgBox "Error #" & Err.Number & " " & Err.Description

    End If



    'Execute the Notepad program


    WshShell.Run "C:\Windows\notepad.exe"


    If Err.Number<>0 Then    

    MsgBox "Unable to launch Notepad program !"

    MsgBox "Error #" & Err.Number & " " & Err.Source & " " & Err.Description

    End If


    set WshShell = Nothing

    Now in XenApp, we just need to publish this VBScript.

    It can be published in XenApp as shown below:

    Note: For more information on publishing in XenApp, refer to my article https://mdaslam.wordpress.com/2010/06/10/application-publish-in-xenapp/


    To test it, if it is working as expected, Launch the published Notepad and click on the menu {File –> Open}. “Open” window will appear. Go to the dropdown list “Look in” and see if the mapped network drive is available or not. It should be available here.

    Application publish in XenApp

    Access Management console is required to publish any application installed on XenApp.

    Below are the steps required to publish an application exe. I have taken Notepad.exe as an example to explain the procedure. It can be used to publish exe of any application.


    1. Citrix Access Management console should be installed on the XenApp farm.
    2. Person who is publishing application icon should have full administrative rights on Access management console.


    1. Double click on the desktop icon “Access Management Console” or launch the exe “CmiLaunch.exe” from "C:\Program Files\Common Files\Citrix\Access Management Console – Framework\". Citrix Access Management console window will be launched. Left side of window will have tree structure as shown below. It has a node for Presentation server and under it, there is a node for XenApp farm. It has different folders under it to manage the farm. For this article, our interest is the “Applications” folder under it.           image 
    2. Right Click on “Applications” folder and Select New –> Create Folder as  shown below:            image
    3. Following screen will appear: image                               Enter the application name and click ok. It will create “Notepad” folder under the applications node.
    4. Right click on “Notepad” folder and select New –> Publish application. “Welcome” screen will appear: Click Nextimage
    5. “Name” screen will appear, add the following details and Click Next:                                                                                     Display Name: Notepad | Application description: Notepadimage
    6. “Type” screen will appear, Keep the default selection and Click Next.                                                                                         Note: Selection needs to be changes in case of application isolation or if server desktop or content needs to be published. We will discuss this more on part 2 of this article.image
    7. “Location” screen will appear, browse to the notepad.exe and click Next. It should fill up the command line and Working directory correctly. If not, add it manually. Do not check Isolation application checkbox.image
    8. “Servers” screen will appear, Click on “Add” button to add all the servers where Notepad has been installed. Servers added here will be having load balancing.image
    9. “Users” screen will appear for adding users who will have access rights on the published icon. Click Add button and it will open “second screen”. On that screen, click on “Add List of Names” button to add the users. “third Screen” will appear. Enter the users into the screen and click “Check Names” button to see the validity of the entered users. Once verified click Ok. Click Ok on second screen and click Next on First screen.                              Note: You can add any number of users from the below screens but the best practice is to have active directory group containing all the required users and that group can be added directly to the below screen. With active directory group it is very easy to manage users. By manage I mean, addition and deletion of users.image
    10. “Shortcut Presentation” screen will appear. Enter “Notepad” folder in the textbox for “Client application folder”. If the user access is through web ICA, do not check the checkbox for “add to the client’s start menu” and “add shortcut to the client’s desktop”.                                                                                 Note: You should enter the folder name that you have created at step 2 above. Users will see the application icon under this folder in their web ICA session. image Check for the application icon displayed on this screen. If you want to change it, click on change icon button, following screen will appear, select the appropriate radio button and get the required application icon and click Ok and then click Next to the parent screen.image
    11. “Publish immediately” screen will appear, select the checkbox for “Configure advanced application settings now” and click next.image
    12. Access control screen will appear: Keep the default options and click Next.image
    13. “Content redirection” screen will appear: select the required extensions and click Next.                                                        Note: For more information, refer to my article: https://mdaslam.wordpress.com/2009/09/09/associating-published-applications-with-file-types/image
    14. “Limits” screen will appear: Depending on the application architecture and the bandwidth, check the checkbox for “Limit instances allowed to run in server farm” and then add Maximum instances. Click Next.image
    15. “Client options” screen will appear: Select the different options based on your requirements like the bandwidth, security or printing requirements. Click Next.                                                  Note: For Client audio, refer to the article https://mdaslam.wordpress.com/2009/11/24/xenapp-legacy-audio/image
    16. “Appearance” screen will appear: Select the appropriate session window size and required color depth. Click Finish.                 Note: For seamless mode, selecting any value under “session window size” will not make any difference. For Color depth, refer to my article: https://mdaslam.wordpress.com/2009/09/22/xenapp-colors-depth-in-published-application-properties/image After this step, application icon will be published and available under “Notepad” folder. Users who are given access to this icon, will be able to see it in Web ICA session.  
    17. In any point of time, if you need to changes any value for this published icon, right click on the published icon under “notepad” folder and click properties. Following screen will appear: Select the node that you want to modify.image You can also change the specific property by doing right click on published icon and selecting “Modify application Properties” and then specific option.
    18. To view information about published icon like servers, configured users, connected users and read only properties, click on “Connected Users” link on the right hand side of access management console. image 


    Citrix Web ICA client and Firefox Mozilla

    If you have installed Citrix Web ICA client before installing Firefox Mozilla, Citrix ICA web link site might give you message to install Citrix ICA Client though you already have it installed.

    To resolve this issue, follow the below steps:

    1. Uninstall the existing Citrix ICA client from Add/Remove program
    2. Launch Firefox Mozilla and browse your internal ICA website, it will give you message to download and install the ICA client somewhere at the bottom of the web page. Click the link and download the client.
    3. Install the downloaded client. Once installed successfully, close the browser and restart it.
    4. It should solve the issue.

    Also, Refer to the support article at Citrix site http://support.citrix.com/article/CTX105973