locked
Environment Variables not working RRS feed

  • Question

  • Weird issue..

    I've got a basis application that implements 2 variables. While sequencing, these variables are put in the deployment xml, as expected;

    <EnvironmentVariables Enabled="true">
            <Include>
              <Variable Name="RAYPATH" Value="[{ProgramFilesX64}]\APPLICATION\lib\;." />
              <Variable Name="PATH" Value="[{ProgramFilesX64}]\APPLICATION\bin;%PATH%" />
            </Include>
    
            <!--
            <Delete>
              <Variable  Name="lib"/>
            </Delete>
            -->
    
    </EnvironmentVariables>
    When published through the management server these variables are not loaded (checked with SET) en therefore the application is not working properly. I've tested this with 2 other apps, same results.

    Is there something that I manually need to set in order for the variables to be loaded when the user logs on/starts the application?

    App-v version 5.1 - latest patches have been installed.
    Environment: 2012 R2

    Monday, March 6, 2017 1:05 PM

Answers

  • This is the script I used. The package is deployed to users, so I created the following Publish/Unpublish scripts (add them to the userconfig, or to the internal manifext file):

      <UserScripts>
        <PublishPackage>
          <Path>POWERSHELL.EXE</Path>
          <Arguments>-ExecutionPolicy RemoteSigned -WindowStyle hidden -Command "&amp; {$sPath =  '[{AppVPackageRoot}]\APPLICATION\lib\' ; [Environment]::SetEnvironmentVariable( 'PATH', ($sPath+';'+[Environment]::GetEnvironmentVariable('PATH','User')),'User') }"</Arguments>
          <Wait RollbackOnError="true" Timeout="120" />
        </PublishPackage>
        <UnpublishPackage>
          <Path>POWERSHELL.EXE</Path>
          <Arguments>-ExecutionPolicy RemoteSigned -WindowStyle hidden -Command "&amp; {$sPath =  '[{AppVPackageRoot}]\APPLICATION\lib\' ; [Environment]::SetEnvironmentVariable( 'PATH', ([Environment]::GetEnvironmentVariable('PATH','User') -replace ([regex]::Escape($sPath)+';'),''),'User') ; if (![Environment]::GetEnvironmentVariable('PATH','User')) { [Environment]::SetEnvironmentVariable('PATH', $null,'User') } }"</Arguments>
          <Wait RollbackOnError="false" Timeout="120" />
        </UnpublishPackage>
      </UserScripts>
    This way the full path to your package is added to the local PATH var. Local software and packages which are not member of the same connectiongroup, can find the application.
    The FTA triggers the virtual app itself, so should find the var.

    Roy Essers


    Friday, March 10, 2017 9:31 AM
  • How did you check those env vars? They will not be set outside the virtual environment, so did you check them inside the virtual environment of your package?

    Roy Essers

    Monday, March 6, 2017 4:06 PM

All replies

  • How did you check those env vars? They will not be set outside the virtual environment, so did you check them inside the virtual environment of your package?

    Roy Essers

    Monday, March 6, 2017 4:06 PM
  • Thx for the reply Roy,

    Never crossed my mind! It is however a command line utility and needs to be run in CMD. Is it possible to enable to variables environment wide?

    Tuesday, March 7, 2017 1:11 PM
  • Since it already runs inside CMD, i guess the shortcut will have /appvve loaded. If you want the environment variables to be local then try using scripts.

    (Please click on Vote as Helpful and/or Mark as Answer, if it has helped you.)

    MVP - Windows and Devices for IT

    app2pack.blogspot.com: app2pack.blogspot.com

    Wednesday, March 8, 2017 9:54 AM
  • Indeed, create a shortcut inside your package which will open a dosbox, from there the env var is available.
    You can aslo script something to create it outside your package, but keep in mind to use the full path to your directory/exe. If needed, I'll dig up the script I used.

    Roy Essers

    Thursday, March 9, 2017 8:59 AM
  • Hi Roy,

    That would be great, thank you.

    Quick question though; it is a cmd utility but it also supports opening files of a particular extention. Does the variables extend to the explorer environment when adding the extention to the package?



    Thursday, March 9, 2017 9:00 AM
  • This is the script I used. The package is deployed to users, so I created the following Publish/Unpublish scripts (add them to the userconfig, or to the internal manifext file):

      <UserScripts>
        <PublishPackage>
          <Path>POWERSHELL.EXE</Path>
          <Arguments>-ExecutionPolicy RemoteSigned -WindowStyle hidden -Command "&amp; {$sPath =  '[{AppVPackageRoot}]\APPLICATION\lib\' ; [Environment]::SetEnvironmentVariable( 'PATH', ($sPath+';'+[Environment]::GetEnvironmentVariable('PATH','User')),'User') }"</Arguments>
          <Wait RollbackOnError="true" Timeout="120" />
        </PublishPackage>
        <UnpublishPackage>
          <Path>POWERSHELL.EXE</Path>
          <Arguments>-ExecutionPolicy RemoteSigned -WindowStyle hidden -Command "&amp; {$sPath =  '[{AppVPackageRoot}]\APPLICATION\lib\' ; [Environment]::SetEnvironmentVariable( 'PATH', ([Environment]::GetEnvironmentVariable('PATH','User') -replace ([regex]::Escape($sPath)+';'),''),'User') ; if (![Environment]::GetEnvironmentVariable('PATH','User')) { [Environment]::SetEnvironmentVariable('PATH', $null,'User') } }"</Arguments>
          <Wait RollbackOnError="false" Timeout="120" />
        </UnpublishPackage>
      </UserScripts>
    This way the full path to your package is added to the local PATH var. Local software and packages which are not member of the same connectiongroup, can find the application.
    The FTA triggers the virtual app itself, so should find the var.

    Roy Essers


    Friday, March 10, 2017 9:31 AM
  • Probably dumb question, but are you specifically loading the deployment xml into the management server?  If you aren't specifically adding it you won't get the env variables.

    I wasn't sure from your post if you are adding the variables post sequencing or that's just what is being written to the xml after sequencing.
    As Tiberivs said, I have seen apps that for whatever reason launching the exes direcly the variables don't get loaded, but if I load cmd.exe first, then the exe, it works.  I don't know about FTAs for those apps though.

    Also FYI if you want to check the env variables a process sees process explorer is great to do that.  It will show 'inside' values vs outside values, but still very useful.

    https://technet.microsoft.com/en-us/sysinternals/processexplorer.aspx?f=255&MSPPError=-2147217396

    Friday, March 10, 2017 9:34 PM
  • Awesome stuff guys! Thank you very much!
    Sunday, March 12, 2017 8:27 PM