Environment variables in MSIX package wont be used by AVD session host

Copper Contributor

Hi,

We've been struggling with environment variables in MSIX packages. The package is created with Microsoft's MSIX Packaging Tool and a script was used under capture. Script is adding environment variables as we can see in the virtual registry after the package has been created. Problem is that session host will not use these environment variable keys. The package works, but there's a SSO feature which doesn't work because of the environment variables. If we add them manually on the session host the SSO feature works fine.

 

We have tried the PSF tool using the fix there for environment variables, but once we change the AppxManifest.xml to point to PsfLauncher32.exe it gives the following error on the session host:

 

16.03.23 15:54:29    Error    403    avd-mgmt-7    error 0x80080207: Failure to get staging session for: \\?\Volume{9dc101d8-0130-4a01-xxxx-a81e0088b390}\applications\xxxx__trsqtdqqj719r.

16.03.23 15:54:29    Error    481    avd-mgmt-7    error 0x80080207: Opening the loose file package from location xxxx__trsqtdqqj719r failed.

 

Any suggestions on what we can try?

9 Replies
We have experienced the same. Did not find a solution to this, so hoping for some inputs here as well.

@OneFiftyLashes

 

Can you confirm which version of PSF are you using? And which fixup?

 

Can you share the MSIX Package with the PSF applied, if possible? You can use the Direct Message of Tech Community to share large files.

@OneFiftyLashes

 

While we are waiting for you to share more info on this, we created our own C++ exe application which uses an env variable, converted to MSIX with the PSF Env Variable fixup. It works perfectly when tested.

 

We also converted the MSIX package to VHDX via MSIX MGR and then App attached - it worked on AVD as well.

 

I'll wait for you to share the application to understand the exact issue, but there's no outright bug that we could find.

Hi, apologies for late response.
The application is SAP logon, which contains a number of sub-applications where one of these need environments variables. The package is full of customer specific info, so unfortunately I can't send it to you. I've used the latest version of PSF framework and tried to use env variable fixup. Could you by share your .json and manifest so I can look for syntax errors on my side?

Hi @OneFiftyLashes 

 

As I mentioned in my previous comment, we had created a test application. The config file was in the format:

 

 

{
    "applications": 
    [
        {
            "id": "ENVVARIABLETEST",
            "executable": "VFS/EnvVariableTest.exe"
        }
    ],
    "processes": 
    [
        {
            "executable": "PsfLauncher.*"
        },
        {
            "executable": ".*",
            "fixups": 
            [
                {
                    "dll": "EnvVarFixup.dll",
          	        "config": 
                    {
                        "envVars": 
                        [
                            {
                                "name": "Test1",
                                "value": "Value1",
                                "useregistry": "false"
                            },
                            {
                                "name": "Test2",
                                "value": "Value2",
                                "useregistry": "false"
                            },
                            {
                                "name": "Test3",
                                "value": "Value3",
                                "useregistry": "false"
                            }
                        ]
                   	}
                }
            ]
        }
    ]
}

 

 

We are also struggling with Environment Variables in MSIX. Tried many configurations without success.
Would you expect to see the Environment Variable listed in the Environment tab for the virtual process in Process Explorer?

Hi @SajidRavat,

 

This is a solution suggested by @TIMOTHY MANGAN on a similar issue from another post:

 

There are two requirements to see the virtualized environment variables:

  1. The process enumerating or querying the variable must be running inside the container.
  2. The process enumerating or querying the variable must use a standard api to perform the action. I believe that Process Explorer uses underdocumented interfaces to read kernel memory (the Process block) directly, which does not know about the virtualized variables.

To determine if the process is in the container you can use an elevated Process Explorer (either inside or outside of the container) and look at the Jobs tab. Alternatively, you can add the "Package Name" and/or "JobID" column in Task Manager.

To see what the app sees, you can create a shortcut to a cmd in the package (to run inside the container), or alternatively you can use the powershell "invoke-CommandInDesktopPackage". In both cases, you use period asterisk method in the json.

You can try this approach to track the environment variables for your scenario.

Have you managed to make this fixup working for PATH Environment Variable?

Adding environment variables to your MSIX packaged applications can be done as session environment variables but unfortunatly it can be a bit of a hassle. Existing environment variables set for both the system and user will be available for any running proces but any new (or changed) variables added to the registry inside the MSIX container will not be loaded when starting a process from the MSIX container. These registry entries are there so the system will know what environment variables to set during system startup and user login. Setting session environment variables can be done by a proces that will set these environment variables and then starting the program that uses these variables (like using a batch file). You can create a script that set these environment variables for the current session but al the script operators like Powershell.exe or cmd.exe are not part of the MSIX container by default and MSIX entry points (shortcuts) can only point to the executable files that are part of the MSIX container. Using the PSF tooling it is possible to execute a powershell script but from my experience the session environment variables are gone when the script is closed and the main program is started. You can let the powershell script also start the main program after setting the session environment variables but i have not tested this yet.

You may also want to take a look at a small tool i created called MSIX Helper that also handles setting (session) environment variables for your applications running from the MSIX container. You can find it on my Github page if you want to try it.

https://github.com/FvGelderen/AutoHotKey/tree/MSIX-Helper/MSIX%20Helper%201.0/Bin

Please read the provided documentation before using it. Any feedback will be appreciated.