Link App-V Packages to “C:\Program Files” Directory

Introduction

In working with sequencing different App-V 5 applications, I’ve found there can be requirements for binaries to exist at absolute paths in C:\Program Files.

This is somewhat problematic because, from what I can find, there is no built-in or easy way to deliver packages to their originally named, and absolute location on a system. No worries, though. We can use some custom scripting to help us out along with the help of System Center Configuration Manager 2012 R2.

Issues

The application that I was working with when I encountered the issue, Meditech Client Server, gave me an error stating that the program was “Not installed in the correct location under C:\Program Files“.

In researching, there wasn’t much info in the way of placing App-V packages into their original location. It always goes somewhere under the App-V folder using the Package ID and Version ID of the published application.

I decided that a symlink could possibly work for this situation since the app seemed to run fine and only complained about the file location. I created a new symlink in C:\Program Files\ with the following command from a PowerShell terminal:

mklink /J "C:\Program Files\APPLICATION_DIRECTORY" C:\ProgramData\App-V\*Package_ID*\*Package_Version*\root

Sure enough mapping the directory as a Windows junction allowed the application to run without issue.

If this application was going to work as an App-V package, an automated way to perform this symlink creation would need to be implemented so that the user would have a working App-V delivery without any additional wait or hassle.

Package Scripts, not

My first attempt at resolution was to use Package Scripts to configure the changes from within the application deployment. It was a logical solution.

The problem here is that the Machine and User Package Event tags don’t provide good timing in making the customization change. The way to make a symlink to an App-V package is by using both the Package and Version IDs, so we need for a script to run after the package has been published in order to use the get-appvclientpackage cmdlet to discover the parameters for mapping.

After playing with the different Event Tags I found that they either initiated too early, before get-appvclientpackage would return any information, or at first run of the App-V application which would cause the associated shortcuts to fail.

Script Installer

To work around this I set up a new Script Installer in SCCM 2012 and created a PowerShell script to perform the symlink creation. This allows us to config the junctions immediately after the application dependencies are met by linking the two in SCCM.

We can then configure Start Menu shortcuts pointing to “C:\Program Files\” during sequencing the App-V 5 applications, or by editing the DeploymentConfig.xml after sequencing. This allows users to launch App-V applications from shortcuts pointing to original absolute paths which will fulfill any path requirements that are hard-coded into the binaries.

Implementation

As mentioned above, the components of this implementation are:

  1. An App-V 5 Application w/ Absolute Path Requirements
  2. Symlink Creation Script
  3. SCCM 2012 R2 Script Installer Application
  4. New App-V Package Shortcuts (if needed)

Let’s start with the script since we’re assuming you already have your application sequenced and added to SCCM.

We’ll then move on to setting the absolute path shortcuts in your DeploymentConfig.xml file after discussing the creation of the Script Installer application in SCCM.

Please note: Don’t distribute the content of your package in SCCM until you’ve made the changes to the shortcuts or you’ll have to redistribute. You can add the package in order to assign the dependency of the Script Installer, but don’t distribute or deploy. Updating shortcuts is in the last section of this guide.

The Script

This PoSH script takes the “Name” of your application, returned in the results of the get-appvclientpackage cmdlet, and the name of your the Program Files folder that we’re creating for the application.

As always, portions to modify in this script are in BOLD & ITALICS:


############################################################################
#  Scriptname: mapPackage.ps1
#
#  Description: This script will map a specified App-V
#               appliaction to "C:\Program Files\"
#
#  By:          Adam Baldwin
#
#  Usage:       Define the value for your package name and
#               for the destination folder name under "C:\Program Files\".
#               This script assumes you are using the default installation
#               source for App-V in "C:\ProgramData\App-V"
############################################################################

# Define the package name to search from present packages
$name = "APPLICATION_NAME"

# Define the name of the folder under "C:\Program Files" to
# map the application
$pathName = "APPLICATION_FOLDER"

# Set the Package object to a string
$package = get-appvclientpackage | where {$_.Name -eq $name}

# Get the Package ID and Version ID
$id = $package.packageID.ToString()
$vid = $package.versionID.ToString()

# Create the symlink mapping command
$cmd = "mklink /J `"C:\Program Files\$pathName`" `"C:\ProgramData\App-V\$id\$vid\root`""

# Run the symlink mapping command
cmd /c $cmd

Put this script into your  application repository. I keep all of my App-V applications, software installers, and script installers in a central place in order to reference and add them to SCCM easily. You can also put this, or any other scripts for Script Installers, on your domain’s netlogon volume. We’ll be using this location in the example below.

Setting up the Script Installer

Now it’s time to configure the Script Installer with the PoSH script that we created above. Be sure that you have your parent App-V application added to SCCM, first, before you create the Script Installer.

In SCCM, navigate to Software Library> Application Management> Applications. 

Right-click and select Create Application.

Check the radio button for Manually specify the application information and click Next

New Manual Application

On the General page, fill in the identifying information for this installer.

Since the function is to set up a specific configuration for an app, in this case to map a symlink to C:\Program Files\, give it some clear descriptions to indicate this behavior.

New Manual General

Click Next and select an Icon and set Categories if you’d like.

On the Deployment Types screen, click Add.

Add Deployment Type

Now you’ll be brought back to a screen that looks like the one we started with, except there is one additional option in the drop-down for Type. 

Click the drop-down and select Script Installer. Click Next to continue.

Script Installer

 

Again, give this installer a good name and description.

Script Installer General

Click Next to continue.

On the Content page, specify the Content location. If using a scripts folder on your netlogon volume, enter:

\\contoso.local\netlogon\scripts\

For the Installation Program, indicate PowerShell.exe with an -f switch pointing to the script created above.

Script Installer Content

Click Next to continue.

On the Detection page, Add a new Clause and specify a Folder for the Type.

Enter C:\Program Files\ for the Path field and enter your application’s folder name in the File or folder name field.

Script Installer Detection

Click OK to save and click Next on the Detection page to continue.

On the User Experience page, decide on your deployment settings. For this application, I’m deploying App-V apps to cloned machines, targeting device groups. In this situation, I’ve decided to use the following:

  1. Install for system if resource is device; otherwise install for user
  2. Whether or not user is logged on
  3. Hidden

Script Installer Experience

Click Next to continue. Click Next through the Requirements page.

On the Dependencies page, click Add and specify a name for the dependency group.

Click Add and browse to your parent application. Check the box and click OK to save.

Dependency

Click OK again to save and click Next to continue to the Summary. 

Verify your settings and click Next to complete.

Update App-V Shortcuts

You can edit the DeploymentConfig.xml file either during sequencing or after. Below I will describe how to make the changes after sequencing.

Open up the folder containing your App-V application and right-click on XXX_DeploymentConfig.xml to Edit or Open With your favorite editor or IDE.

Search for “<shortcut>” and find the entry with the Name and Target of the shortcut you’d like to update.

Once you’ve found your shortcut object, change the value for <Target> to point to your Symlink that we created with the Script Installer. Be sure to put quotes around your path name.

My particular application that was not working was Meditech Client Server. So you can see in my screen shot below, I’ve changed the target for the shortcut to point to an absolute path in C:\Program Files\ rather than to the App-V directory. Once the application is published, the dependent Script Installer will run and make this path accessible and create a seemless experience for the user.

Deployment Config

 

Once this is set, Distribute the content of your App-V app and the Script Installer to your Distribution Point and Deploy to your liking.

Summary

App-V is a great platform for delivering applications, but some, especially legacy applications, can be problematic because of the way they were coded.

If you find any applications that require absolute paths to the binaries, this method is the solution for you.

Let me know if you have any questions or comments below!

~Cheers!

ScriptdEEZ

Advertisements