Microsoft App-V Self service tool

Share Button

One of my customers asked for a ‘self service tool’ for their users to remove pkg files from their profiles. Because there’s no direct relation between the registry values and the location of the pkg files I had to be creative with a search within this script:

#=================================================================

# AUTHOR: Kees Baggerman

# COMPANY: Inter Access B.v.

# DATE: 21-02-2010

# Version: 0.2

# Puts all the app-v applications in an drop down menu

# and removes the PKG files from the selected application.

#=================================================================

if (Test-Path HKLM:SOFTWAREMicrosoftSoftgrid4.5ClientApplications)

{

# Get all subkeys from HCKU:

$HKLM = 2147483650

$key = “SOFTWAREMicrosoftSoftgrid4.5ClientApplications”

$reg = [wmiclass]‘\.rootdefault:StdRegprov’

$subkeys = $reg.EnumKey($HKLM, $key)

$subkeys.snames

# Put all of the registry keys in an array and put that in a dropdown menu.

[array]$DropDownArray = $subkeys.snames

# This Function Returns the Selected Value and Closes the Form

function Return-DropDown {

$Choice = $DropDown.SelectedItem.ToString()

$Form.Close()

function Get-RegistryValue($key, $value) {

(Get-ItemProperty $key $value).$value

}

$AppName = Get-RegistryValue HKLM:SOFTWAREMicrosoftSoftgrid4.5ClientApplications$Choice `

AppPath

$AppName = $AppName.Substring(1,8)

Function FindFolder

{

$input | Where-Object {$_.Name -match $AppName}

}

$AppLoc = Get-ChildItem -Path $Env:AppData | FindFolder

Remove-Item $Env:AppData$AppLoc -recurse

}

[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)

$Form = New-Object System.Windows.Forms.Form

$Form.StartPosition = “CenterScreen”

$Form.width = 300

$Form.height = 150

$Form.Text = ”AppVPKGRemover”

$DropDown = new-object System.Windows.Forms.ComboBox

$DropDown.Location = new-object System.Drawing.Size(100,10)

$DropDown.Size = new-object System.Drawing.Size(130,30)

ForEach ($Item in $DropDownArray) {

$DropDown.Items.Add($Item)

}

$Form.Controls.Add($DropDown)

$DropDownLabel = new-object System.Windows.Forms.Label

$DropDownLabel.Location = new-object System.Drawing.Size(10,10)

$DropDownLabel.size = new-object System.Drawing.Size(100,20)

$DropDownLabel.Text = “Applications”

$Form.Controls.Add($DropDownLabel)

$Button = new-object System.Windows.Forms.Button

$Button.Location = new-object System.Drawing.Size(100,50)

$Button.Size = new-object System.Drawing.Size(100,20)

$Button.Text = “Remove files”

$Button.Add_Click({Return-DropDown})

$form.Controls.Add($Button)

$Button1 = new-object System.Windows.Forms.Button

$Button1.Location = new-object System.Drawing.Size(100,75)

$Button1.Size = new-object System.Drawing.Size(100,20)

$Button1.Text = “Quit”

$Button1.Add_click({ $form.close() })

$form.Controls.Add($Button1)

$Form.Add_Shown({$Form.Activate()})

$Form.ShowDialog()

}

else

{

[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)

$Form = New-Object System.Windows.Forms.Form

$Form.StartPosition = “CenterScreen”

$Form.width = 300

$Form.height = 150

$Form.Text = ”AppVPKGRemover”

# Create the label control and set text, size and location

$label = New-Object Windows.Forms.Label

$label.Location = New-Object Drawing.Point 100,50

$label.Size = New-Object System.Drawing.Size(125,20)

$label.text = “App-V is not installed!”

$form.controls.add($label)

$Button1 = new-object System.Windows.Forms.Button

$Button1.Location = new-object System.Drawing.Size(100,75)

$Button1.Size = new-object System.Drawing.Size(100,20)

$Button1.Text = “Quit”

$Button1.Add_click({ $form.close() })

$form.Controls.Add($Button1)

$Form.Add_Shown({$Form.Activate()})

$Form.ShowDialog()

}

A small disclaimer: Powershell and scripting is not my day to day work so it’s possible that this script has a couple of flaws. I did a lot of copy/pasting from a couple of blogs and MS posts but feel free to use this script. It’s a draft version thus I can’t guarantee that this will work but in my test environment it does. If you have additional comments just drop a comment so I can optimize this script.

Share Button
  1. k.baggermank.baggerman02-22-2011

    Patrick S. :

    The WMI namespace for App-V has an Application class that you could use to get the App-V apps. This would probably be a little safer than reading registry keys. You could also use this class to get the application’s package GUID, which is the basis for part of the PKG folder name.

    For example, to fill in your drop-down box…

    $apps = Get-WmiObject -Class “Application” -Namespace “rootmicrosoftappvirtclient” |
    Sort-Object Name
    foreach ($app in $apps)
    {
    $DropDown.Items.Add([System.String]::Format(“{0}”, $app.Name))
    }

    Patrick, thanks for your comments but my test enviroment doesn’t support the namespace in combination with the Class application so it will take some time to re-write the script using WMI. I agree that WMI is a bit safer than plain registry keys.

  2. Patrick S.Patrick S.02-22-2011

    The WMI namespace for App-V has an Application class that you could use to get the App-V apps. This would probably be a little safer than reading registry keys. You could also use this class to get the application’s package GUID, which is the basis for part of the PKG folder name.

    For example, to fill in your drop-down box…

    $apps = Get-WmiObject -Class “Application” -Namespace “rootmicrosoftappvirtclient” |
    Sort-Object Name
    foreach ($app in $apps)
    {
    $DropDown.Items.Add([System.String]::Format(“{0}”, $app.Name))
    }

Leave a Reply