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.

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


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.


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


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


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.


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

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…


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


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


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


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}


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.


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.


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

Comments (2)

  1. Dan Gough says:

    Interesting, I have an ancient but related post here:

    Shortcuts to vbs files launch inside the virtual environment, but I never thought to check hta files. If memory serves correct there is a list of file extensions to virtualise somewhere in the client registry, perhaps adding hta to this list would be a good idea!

    1. Dafalk says:

      Hi Dan,

      Thanks for the comment and your linked post on this.

      This post was about how the sequencer determines whether the Target is in the package or not, if the TargetInPackage is set to false and you try and run a StartVirtualEnvironment script then it won’t run.

      Your post was interesting as well, so I recreated it to show what the sequencer thinks when you capture each file type.

      <Application Id="[{AppVPackageRoot}]\OS_Version.cmd" Origin="Application" TargetInPackage="true">
      <Application Id="[{AppVPackageRoot}]\vbpopup.vbs" Origin="Application" TargetInPackage="true">
      <Application Id="[{System}]\cscript.exe" Origin="Application" TargetInPackage="false">
      <Application Id="[{System}]\reg.exe" Origin="Application" TargetInPackage="false">
      <Application Id="[{System}]\wscript.exe" Origin="Application" TargetInPackage="false">
      <Application Id="[{AppVPackageRoot}]\OS_Version.hta" Origin="User" TargetInPackage="false">
      <Application Id="[{AppVPackageRoot}]\OS_Version.reg" Origin="User" TargetInPackage="false">

      So out of the above the StartVirtualEnvironment script would only run with “OS_Version.cmd” and “vbpopup.vbs”.

      The “VirtualizableExtensions” addition of hta makes no difference.


Skip to main content