App-V 5 – Scripting and TargetInPackage

Hi all,

The following post with go into detail about why an App-V script doesn’t run when launching an application, its related to how the App-V Sequencer captures an application.

The first thing to note is that what I’m sequencing is an HTA Application which customers use and deliver to their users. A description of what an HTA Application is below:

HTML Applications (HTAs) provide a way for you to wrap your scripts up in a graphical user interface, an interface replete with check boxes, radio buttons, drop-down lists and all those other Windows elements you’ve grown to love.

https://technet.microsoft.com/en-us/library/ee692768.aspx

The HTA that’s been sequenced shows which Operating System Version your using:

HTA

What I’ve done is created an exe in the scripts folder within the package that needs to be ran on "StartVirtualEnvironment" user script, a custom UserConfig.xml file has been created to add the script.

UserConfig_Script

The script has been added to the XML, now to add it to the client using PowerShell with the "-DynamicUserConfigurationPath" parameter:

UserConfig_Publish

Now when you run the application no script is ran and the application launches as normal.

OS_App_Launch

The question is how do you check if any App-V scripts have run and that’s where the App-V Operational Log comes in handy as it logs all "Execute Embedded Scripts" events, e.g.

ExecuteEmbeddedScript

For more information on the Operational Event log check out one of my posts:

https://blogs.technet.microsoft.com/virtualshell/2016/04/12/app-v-5-operational-log-usage/

The Operational Event Log doesn’t show any "Execute Embedded Scripts" event so how do you figure out what’s happening here?

If you launch the application and check "Get-AppvVirtualProcess" you will see that there are no Virtual Processes for OS_Version.hta…

AVVP

Next was to use "Start-AppvVirtualProcess" to open the package to see what happens and interestingly the Start.exe "AppDemo1" launches….

Start-VirtProc

In the Operational Event Log, you see the “Execute Embedded Scripts” event log entry for Start.exe.

ExecuteEmbeddedScript_Start.exe

And with “Get-AppvVirtualProcess” you will see Start.exe running…

AVVP_Start

So why doesn’t the script run when you launch the shortcut for the application?

If you check task manager after you have launched the application, you will see that the EXE that has launched the application is mshta.exe which resides in the C:\Windows\SysWOW64 directory.

 "C:\Windows\SysWOW64\mshta.exe" "C:\Users\username\AppData\Local\Microsoft\AppV\Client\Integration\3859F634-0043-4494-B409-57593516FF21\Root\OS_Version.hta" {1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}{1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}

mshta

If you’re wondering what the "{1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}{1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}" is after the .hta has been called, its specified in the operating system Classes key (HKCR) for the htafile.

htafile_classes

The above is a lot of context about what happens but what’s the cause of why the script doesn’t run?

Well it’s down to a setting in the AppxManifest.xml file called "TargetInPackage". If you open the AppxManifest.xml file from the package and browse to the Applications section, you will see that the TargetInPackage is set to "false" for OS_Version.hta.

TIP_AppX

So, what does "TargetInPackage" mean and why doesn’t it start a user based script???

When you sequence an application, the sequencer determines where the EXE is that launches the application. In this instance when you launch a HTA file, mshta.exe isn’t part of the package as it’s a windows component so it sets the flag for that EXE that it isn’t in the package. As the EXE isn’t in the package the App-V client doesn’t run hta within the virtual environment it runs it natively on the operating system. As the script that I’m testing with is "StartVirtualEnvironment" as the environment hasn’t started no script is ran.

 "C:\Windows\SysWOW64\mshta.exe" "C:\Users\username\AppData\Local\Microsoft\AppV\Client\Integration\3859F634-0043-4494-B409-57593516FF21\Root\OS_Version.hta" {1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}{1E460BD7-F1C3-4B2E-88BF-4E770A288AF5}

There are multiple applications that will have the same behaviour e.g. HTA, Internet Explorer shortcut or any other windows component.

Hope this helps you understand why a package script doesn’t run if the TargetInPackage is set to false.

David Falkus | Senior Premier Field Engineer | Application Virtualization, PowerShell, Windows Shell