How to Set Up an Environment Variable in MSIX to Directory and File Paths

Written by Horatiu Vladasel · November 25th, 2022

#MSIX #TIPS

Environmental variables, as their name implies, are variables that specify the environment in which a program runs.

The data in an environment variable is always saved as a string, and can be used by the operating system itself or the programs installed on the device.

In this article, we will go through the process of overcoming one of the MSIX limitations: setting up a traditional environment variable to a folder/directory path.

First, let’s see what are the two types of environmental variables:

1. User Environment Variables – they can be accessed only by the current logged on user

2. System Environment Variables – they can be accessed and are globally available to all users.

Types of Environmental Variables

On the other hand, both User and System Environment Variables can store Directory/Folder paths and File paths.

Directory/Folder paths and File paths.

Environment Variables and MSIX limitation with App Execution Aliases

When Microsoft released MSIX, they didn’t bring over the environment variables. However, you still can achieve pretty much the same thing by using the App Execution Aliases.

The issue is that with the App Execution Aliases you can specify only a file path target, not a directory/folder path.

NoteCheck out our MSIX - AppExecutionAlias article, if you want to find out more about App Execution Aliases and how to set it up within your MSIX package.

This limitation could turn out to be a dead end if you need to convert a legacy Win32 app to MSIX and the application requires an environment variable from a specific directory/folder path in order to work as designed.

How can you overcome this? Let's take a look.

MSIX requires an Environment Variable from a directory: The solution

If you are familiar with MSIX, then you may already know that many MSIX limitations can be overcome by using the Package Support Framework (PSF).

At the moment, Microsoft Package Support Framework does not contain a fixup for Environment Variables limitation.

Here are some solutions that overcome this limitation:

  1. Your can create your own fixup and inject that into your MSIX
  2. You can use the EnvVar fixup created by Tim Mangan that you can download from here.
  3. Use Advanced Installer’s GUI for configuring environment variables

In this article, we will take a closer look at the third solution.

Advanced Installer Solution to MSIX Environment Variable Limitations

In Advanced Installer, we developed our own support for this kind of limitation without the need to write any code or manually inject the Package Support Framework into the MSIX package.

All you need to do is go to the Environment page and set up your Environment Variable as you would normally do for MSI packages.

So, if you want to set up a System Variable called MYAPP, you need to point it to the installation folder - in our scenario APPDIR.

Set Up System Variable

And that’s all.

Now, if you build and install the MSIX package on a machine, you can see that the environment variable (MYAPP) you set up earlier from the Environment page is visible within the MSIX container.

Environment Variable Visible within MSIX Container

Furthermore, we also integrated all MSI Environment Variables support into MSIX – meaning that you can now update (prepend or append) an existing Environment Variable (e.g. Path).

Append the Path Environment Variable in Advanced Installer

The process is similar to our solution for MSI environment variables.

This time you need to choose Append for the Behavior option – in our case we want to append the Path Environment Variable.

Append the Path Environment Variable

And now, as you can see, the Path Environment Variable got appended with the installation folder for our application.

Path Environment Variable Appended with Installation Folder

TipYou can use the same solution to declare and set up an Environment Variable targeting a file path.

Conclusion

Now you know how to declare and set up a traditional Environment Variable within MSIX packages – no coding or needing to manually inject the Package Support Framework.

Keep in mind that Environment Variables declared this way are visible only within the MSIX container, but that will do the trick and help you fix this specific MSIX limitation.

Thanks to its easy-to-use GUI, Advanced Installer comes up with solutions constantly to help you overcome MSIX limitations.

Let us know if there's any other MSIX limitation that you'd like us to write about.

Subscribe to Our Newsletter

Sign up for free and be the first to receive the latest news, videos, exclusive How-Tos, and guides from Advanced Installer.

Comments: