Month: March 2014

App-V 5.0 Script to Update Environment Path

Posted on

The following script can be used as an example for to update the Windows system Environment variable PATH to include the root of the virtual file system for the package.  The script can be included as part of an App-V 5.0 dynamic configuration file (e.g. DeploymentConfig.xml).

@echo off
:: This script is intended to be embeded in an App-V 5.0 package for
::    the purpose of adding .exe files into command path.
:: It will retrive the current working directory of the script folder,
::    change the value from ending with \Scripts to \Root, and finally
::    update the PATH environment variable to include the directory path.


:: Get the path of this script
set newpth=%~dp0
:: Change the value from \Scripts to \Root
set newpth=%newpth:scripts=Root\bin%
echo NEWPTH = %newpth%

:: Get existing PATH variable
for /F "tokens=2* delims= " %%f IN ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path ^| findstr /i path') do set OLD_SYSTEM_PATH=%%g

:: Determine if the new path already exists
echo.%OLD_SYSTEM_PATH% | findstr /i /c:%newpth% 1>nul

If errorlevel 1 (
  echo NEWPTH pattern not found
  setx PATH "%path%;%newpth%;" -m
) Else (
  echo NEWPTH pattern found, skipping

:: for troubleshooting, uncomment the pause below
:: pause

Then use this within the UserConfig of the DeploymentConfig.xml

        <Arguments>/c [{AppVPackageRoot}]\..\Scripts\newpath.bat</Arguments>
        <Wait RollbackOnError="true" Timeout="60"/>