App-V Context Menu Shortcuts

January 18th, 2017 - Wednesday

Written by Vigneshwaran Velayudham



Application Packagers usually spend some time in testing the virtualized applications in a standalone machine to confirm that the package is working fine and is issue free. In order to test the virtualized package using .appv, we need to open up a Powershell window as an administrator, and type in some Powershell commands. Though the commands are simple, they often require some time, which I feel can be reduced drastically. There are quite a few tools that provide options to test the packages without any need to do manual work, but not all customers want to use them in their environment. Hence, an idea to use a simple trick to install the App-V virtual packages in a single click without any need to open Powershell and type commands in a standalone machine. This can be achieved by a simple registry tweak to publish the virtual packages either globally, or to a user by right clicking an appv file, and using the context menu shortcut option.

Register keys

Copy the below code in Notepad, and save it as .reg format. After saving, run the file to register the keys.

          Windows Registry Editor Version 5.00

          [HKEY_CLASSES_ROOT\.appv]
          @="appvex"

          [HKEY_CLASSES_ROOT\appvex]

          [HKEY_CLASSES_ROOT\appvex\shell]

          [HKEY_CLASSES_ROOT\appvex\shell\Publish Globally]
          @="&Publish Globally"

          [HKEY_CLASSES_ROOT\appvex\shell\Publish Globally\command]
          @="cmd /c start /b /wait powershell.exe  -nologo -ExecutionPolicy bypass -command \"&
          {add-appvclientpackage '%1' |publish-appvclientpackage -global|mount-appvclientpackage}\""

          [HKEY_CLASSES_ROOT\appvex\shell\Publish to User]
          @="Publish to &User"

          [HKEY_CLASSES_ROOT\appvex\shell\Publish to User\command]
          @="cmd /c start /b /wait powershell.exe  -nologo -ExecutionPolicy bypass -command \"&
          {add-appvclientpackage '%1' |publish-appvclientpackage |mount-appvclientpackage}\""
      

After registering the key, you should be able to see the below highlighted context menu shortcuts when you right-click any appv file. To publish globally, click on the Publish Globally shortcut and vice versa.

Note: This doesn't add the dynamic configuration (deployment/user config) file while adding/publishing. To add deployment/user config file along with the package then follow the steps below. This requires additional powershell script.

Copy the below code in Notepad, and save it as .reg format. After saving, run the file to register the keys.

        Windows Registry Editor Version 5.00

        [HKEY_CLASSES_ROOT\.appv]
        @="appvex"

        [HKEY_CLASSES_ROOT\appvex]

        [HKEY_CLASSES_ROOT\appvex\shell]

        [HKEY_CLASSES_ROOT\appvex\shell\Publish Globally]
        @="&Publish Globally"

        [HKEY_CLASSES_ROOT\appvex\shell\Publish Globally\command]
        @="cmd /c start /b /wait powershell.exe -nologo -ExecutionPolicy bypass -file
        \"c:\\Publish globally.ps1\" \"%1\""

        [HKEY_CLASSES_ROOT\appvex\shell\Publish to User]
        @="Publish to &User"

        [HKEY_CLASSES_ROOT\appvex\shell\Publish to User\command]
        @="cmd /c start /b /wait powershell.exe -nologo -ExecutionPolicy bypass -file
        \"c:\\Publish to user.ps1\" \"%1\""
      


Publish Globally

Copy the below code in a notepad, and save it as Publish globally.ps1. Place this file in C:\drive. If you are planning to keep it elsewhere, then edit the above registry entry accordingly.

        #Import App-V Client Module
        Import-Module AppvClient

        #Enable execution of scripts
        Set-AppvClientConfiguration -EnablePackageScripts 1

        #get appvfile

        $appvfile = "$args"

        Write-Host $appvfile

        #get appv file location

        $appvlocation = $appvfile.lastindexof("\")

        $location = $appvfile.substring(0,$appvlocation)

        Write-Host $location

        Write-Host "Path is valid = $(Test-Path $location)"

        Set-Location $location

        #get _Deploymentconfig file

        ForEach ($file in "$location")
        {
        $Name=Get-ChildItem $file
          for ($i = 0; $i -lt $Name.count; $i++)
          {
            if ($Name[$i].Extension -eq ".xml")
           {
            $xmlFileName = $Name[$i].FullName
            if ($xmlFileName.contains("_DeploymentConfig"))
            {
             $deploymentconfigfile = $xmlFileName
        Write-Host "$deploymentconfigfile"
            }
           }
          }
        Add-AppvClientPackage -path $appvfile -DynamicDeploymentConfiguration
        "$deploymentconfigfile" | Publish-AppvClientPackage -Global  | Mount-AppvClientPackage
        }
        


Publish to User

Copy the below code in a notepad and save it as Publish to user.ps1. Place this file in C:\drive. If you are planning to keep it elsewhere, then edit the registry entry accordingly.

          #Import App-V Client Module
          Import-Module AppvClient

          #Enable execution of scripts
          Set-AppvClientConfiguration -EnablePackageScripts 1

          #get appvfile

          $appvfile = "$args"

          Write-Host $appvfile

          #get appv file location

          $appvlocation = $appvfile.lastindexof("\")

          $location = $appvfile.substring(0,$appvlocation)

          Write-Host $location

          Write-Host "Path is valid = $(Test-Path $location)"

          Set-Location $location

          #get _userconfig file

          ForEach ($file in "$location")
          {
          $Name=Get-ChildItem $file
            for ($i = 0; $i -lt $Name.count; $i++)
            {
              if ($Name[$i].Extension -eq ".xml")
             {
              $xmlFileName = $Name[$i].FullName
              if ($xmlFileName.contains("_UserConfig"))
              {
               $UserConfigfile = $xmlFileName
          Write-Host "$UserConfigfile"
              }
             }
            }
          Add-AppvClientPackage -path $appvfile | Publish-AppvClientPackage -DynamicUserConfigurationPath
          "$UserConfigfile"| Mount-AppvClientPackage
          }
        


Context Menu Preview

When you right click any appv file, it will show the two context menu shortcuts. If you want to publish globally along with the deploymentconfig file, then click on Publish Globally and to publish to a user along with the Userconfig file then click on Publish to User.

Registry Peak

Disclaimer - Test the above scripts with caution, as I don't hold any responsibility for any problem caused. This is issued for experimental purpose only.