App-V 5.0 Demo – User scripting / StartProcess

Posted on Updated on

This is the walk-through for demo #3 from my Microsoft Master webcast on App-V 5.0 scripting.  For the full webcast information, visit https://t3chn1ck.wordpress.com/2014/02/03/playback-of-microsoft-master-app-v-5-0/.

This demo is on scripting for a process to run when a user launches the application.  I’m using the game of Sudoku (obtained from SourceForge) and when it is launched by the user, it opens a text file on the “rules” of the game.  For this example, I am using the standalone App-V infrastructure, not ConfigMgr 2012 R2.

  1. The package has already been sequenced.  It’s just a simple set of files (and the main .exe) that I copied into the Program Files directory.  After sequencing, I added the PowerShell script to perform the operation.appv-sudoku-demo01
  2. The PowerShell script will obtain it’s current working directory and then execute the text file specified.
    
    function Get-ScriptDirectory {
      $Invocation = (Get-Variable MyInvocation -Scope 1).Value
      Split-Path $Invocation.MyCommand.Path
    }
    
    $vfsPath = Join-Path (Get-ScriptDirectory) ""
    write-host $vfsPath
    
    Set-Location $vfsPath
    Invoke-Item "Sudoku Rules.txt"
    
  3. In the UserConfig.xml we define that whenever Sudoku.exe is launched, then App-V will execute powershell.exe with the command line to run our .ps1 script.
    <UserScripts>
    <StartProcess RunInVirtualEnvironment="false">
    <Path>powershell.exe</Path>
    <Arguments>-ExecutionPolicy Bypass -File "[{AppVPackageRoot}]\..\Scripts\OpenRules.ps1"</Arguments>
    <Wait RollbackOnError="true"/>
    <ApplicationId>[{AppVPackageRoot}]\Sudoku.exe</ApplicationId>
    </StartProcess>
    </UserScripts>
    
  4. Now add the package into the App-V console and assign to a user group as per standard process.  Then follow my guideline on how to activate the custom UserConfig scripts.  Finally, with the test user, update the App-V client so that Sudoku becomes available.

Once Sudoku is launched, the PowerShell script will very quickly execute (so fast that I cannot capture a screen shot).  But we will have the text file open with rules for learning how to play the game!

appv-sudoku-demo02

Furthermore, the App-V operational events show execution of the script.

appv-sudoku-demo03

Advertisements

2 thoughts on “App-V 5.0 Demo – User scripting / StartProcess

    Playback of Microsoft Master App-V 5.0 | MS Tech BLOG said:
    February 16, 2014 at 2:21 pm

    […] App-V 5.0 Demo – User scripting / StartProcess | t3chn1ck […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s