«

»

Jul 12 2014

Print this Post

User Environment Variables in App-V 5.0 with SP1, SP2 and SP2 Hotfix 4

image_pdfimage_print

Dan Gough wrote an excellent article named: User Environment Variables in App-V 5 Scripts. To summarize: it is about the fact that environment variables are not shown correctly in AppV 5.0.
However: the question is: is this still the case? Time to investigate!

To test this, I re-used an old package: Firefox 24. It does not need any startup-scripts, but it is an ideal candidate for testing.

I have done the following:

  1. I created a VB script with the following content:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    
    ' ===========================================================================
    ' Example of environment variables when running as a script.
    ' ===========================================================================
     
      Option Explicit
     
      Dim objShell             : set objShell        = CreateObject("WScript.Shell")
      Dim strText              : strText             = ""
      Dim strUserShellFolders  : strUserShellFolders = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
      Dim strShellFolders      : strShellFolders     = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
      Dim strVolatileEnv       : strVolatileEnv      = "HKCU\Volatile Environment"
     
      strText = strText & "Displaying the various variables when running scripts in AppV 5.0." & vbCrlf
      On Error Resume Next
      strText = strText & "AppV 5.0 Client version:   " & objShell.RegRead("HKLM\SOFTWARE\Microsoft\AppV\Client\Version")
      On Error Goto 0
      strText = strText & vbCrlf & vbCrlf
     
     
      ' Start with environment variables
      strText = strText & "Environment variables:" & vbCrlf
      strText = strText & " - APPDATA:       " & objShell.ExpandEnvironmentStrings("%APPDATA%") & vbCrlf
      strText = strText & " - LOCALAPPDATA:  " & objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & vbCrlf
      strText = strText & " - USERNAME:      " & objShell.ExpandEnvironmentStrings("%USERNAME%") & vbCrlf
      strText = strText & " - USERPROFILE:   " & objShell.ExpandEnvironmentStrings("%USERPROFILE%") & vbCrlf & vbCrlf
     
      ' Use HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
      strText = strText & "Use " & strUserShellFolders & ":" & vbCrlf
      strText = strText & " - AppData:       " & objShell.RegRead(strUserShellFolders & "\Appdata") & vbCrlf
      strText = strText & " - Local AppData: " & objShell.RegRead(strUserShellFolders & "\Local Appdata") & vbCrlf
      strText = strText & " - Desktop:       " & objShell.RegRead(strUserShellFolders & "\Desktop") & vbCrlf & vbCrlf
     
      ' Use HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
      strText = strText & "Use " & strShellFolders & ":" & vbCrlf
      strText = strText & " - AppData:       " & objShell.RegRead(strShellFolders & "\Appdata") & vbCrlf
      strText = strText & " - Local AppData: " & objShell.RegRead(strShellFolders & "\Local Appdata") & vbCrlf
      strText = strText & " - Desktop:       " & objShell.RegRead(strShellFolders & "\Desktop") & vbCrlf & vbCrlf
     
      ' Use HKEY_CURRENT_USER\Volatile Environment
      strText = strText & "Use " & strVolatileEnv & ":" & vbCrlf
      strText = strText & " - APPDATA:       " & objShell.RegRead(strVolatileEnv & "\APPDATA") & vbCrlf
      strText = strText & " - LOCALAPPDATA:  " & objShell.RegRead(strVolatileEnv & "\LOCALAPPDATA") & vbCrlf
      strText = strText & " - USERNAME:      " & objShell.RegRead(strVolatileEnv & "\USERNAME") & vbCrlf
      strText = strText & " - USERPROFILE:   " & objShell.RegRead(strVolatileEnv & "\USERPROFILE") & vbCrlf
     
      msgbox strText,,"Results from environment variables"
  2. Modified the package by adding the file in the scripts folder:
    Add the vbscript in sequencer

    Add the vbscript in sequencer

  3. Installed AppV 5.0 with SP1 on a client
  4. Logged in with an account with standard user rights.
  5. Started PowerShell as admin and installed Firefox. Also I enabled packaging scripts:
    Powershell commands to add the package.

    Powershell commands to add the package.

  6. Started Firefox:
    The environment variables are shown incorrect,

    The environment variables are shown incorrect,

  7. Upgraded the client to SP2:
    Install the client.

    Install the client.


    Reboot the computer.

    Reboot the computer.

  8. Started Firefox:
    The environment variables are shown correctly,

    The environment variables are shown correctly,

  9. Upgraded the client to SP2 with HF4:
    Install the client.

    Install the client.


    Reboot the computer.

    Reboot the computer.

  10. Started Firefox:
    The environment variables are shown correctly,

    The environment variables are shown correctly,

To summarize: if you want to use scripts and environment variables are needed, then use at least SP2. If you cannot upgrade the client, then use the HKCU\Volatile Environment.

Permanent link to this article: https://www.vroom.cc/wordpress/user-environment-variables-in-app-v-5-0-with-sp1-sp2-and-sp2-hotfix4/