AppV 5 - Measuring RegistryStaging load times

15 Dec 2014

Per my previous posting, I have an issue where the AppVClient.exe consumes significant CPU resources upon application launch. From a Microsoft forum where another member did some further investigation, he discovered that the slowness and delayed launch times are related to registry staging. To confirm and measure the impact of registry staging I wrote a script that measures the length of time it takes to finish registry staging for all AppV5 applications on your computer/server.

#import AppVClient module
ipmo *appv*
 
#get all appv packages
$apps = Get-AppvClientPackage
$obj = @()
 
#Get connection group applications
$connApps = (Get-AppvClientConnectionGroup).GetPackages()
 
#remove connecion-group applications from the list
[System.Collections.ArrayList]$appList = $apps
foreach ($connApp in $connApps) {$appList = $appList | ? { $_.name -ne $connApp.Name }}
 
 
#for each (non-connection group) appv package...
foreach ($app in $appList) {
$prop = New-Object System.Object
 
#get each appv package ID and version ID
$package = ($app.packageID).ToString()
$version = ($app.versionID).ToString()
 
#start a blank cmd.exe in the environment (this kicks off the AppV5 registry staging)
Start-AppvVirtualProcess -AppvClientObject (Get-AppvClientPackage $app.name) cmd.exe
 
#measures the length of time it takes before registry staging is finished (resolution is 1s)
$command = measure-command {
    do {
    write-host "Testing: " $app.name
        sleep 1
       }
       until (Test-Path "HKLM:\SOFTWARE\Microsoft\AppV\Client\Packages\$package\Versions\$version\RegistryStagingFinished")
       write-host $app.name
       $appvProcess = get-appvVirtualProcess
       stop-process $appvProcess -force
    }
    $prop | Add-Member -type NoteProperty -name Package -value $app.Name
    $prop | Add-Member -type NoteProperty -name RegistryStagingTime -value $command.TotalSeconds
    $obj += $prop
}
$obj | export-csv RegistryStagingTime.csv -NoTypeInformation
 
#for each connection group package...
$conGroups = Get-AppvClientConnectionGroup
foreach ($group in $conGroups) {
$prop = New-Object System.Object
 
#get each connection group package ID and version ID
$package = ($group.groupID).ToString()
$version = ($group.versionID).ToString()
 
#start a blank cmd.exe in the environment (this kicks off the AppV5 registry staging)
Start-AppvVirtualProcess -AppvClientObject ($group) cmd.exe
 
#measures the length of time it takes before registry staging is finished (resolution is 1s)
$command = measure-command {
    do {
    write-host "Testing: " $group.name
        sleep 1
       }
       until (Test-Path "HKLM:\SOFTWARE\Microsoft\AppV\Client\PackageGroups\$package\Versions\$version\RegistryStagingFinished")
       write-host $group.name
       $appvProcess = get-appvVirtualProcess
       stop-process $appvProcess -force
    }
    $prop | Add-Member -type NoteProperty -name Package -value $group.Name
    $prop | Add-Member -type NoteProperty -name RegistryStagingTime -value $command.TotalSeconds
    $obj += $prop
}
 
#exports all information to csv file
$obj | export-csv RegistryStagingTime.csv -NoTypeInformatio

What this script does is iterate through all your AppV5 applications and then loads a cmd.exe with the AppV environment. It then checks for the RegistryStagingFinished registry key, and once it is found, it moves on to the next program. It records all this information than exports it as a CSV file.

By utilizing this script as a AppV prelaunch/startup script we can optimize our users first application startup times and reduce CPU utilization of first-run applications.