kerenor
Posts: 13
Joined: Mon Mar 20, 2023 3:32 pm

Environment Variables don't work in MSIX?

I set an env var to a simple string (Using the Environment tab, as explained in the tutorial here- https://www.advancedinstaller.com/msix- ... ables.html), and in my app I read that env var - it is still unset.
Also when opening cmd in the app with Hover , the env var is unset.
This is the same whether I check the "system variable" checkbox or not.
Perhaps related to the "Component" part? I set the Component to be APPDIR, but honestly I'm not sure what the component should be (I want the env var to apply globally for all processes & dlls in the MSIX)

* Edit - it looks like the env var is set in the executable that is the default application for my MSIX, but it starts new processes using ShellExecute, and in those processes the env var doesn't exist (as well as when starting cmd with hover)

thanks
Keren
Catalin
Posts: 7664
Joined: Wed Jun 13, 2018 7:49 am

Re: Environment Variables don't work in MSIX?

Hello Keren,

As the article suggests:
This is a bit different with MSIX since only environment variables that lead to executables can be defined within it, and in MSIX we must understand that these are called App Execution Aliases.

In a MSIX package, the environment variables are available only in the container, thus the environment variables created by an MSIX package cannot be accessed outside the container.
Basically the App Execution Alias will point to your executable, e.g.:

"My super long name application.exe" --> "mslna"

if you open CMD and type mslna, it should launch the executable.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kerenor
Posts: 13
Joined: Mon Mar 20, 2023 3:32 pm

Re: Environment Variables don't work in MSIX?

Thanks for your reply, I'm afraid it actually doesn't really help; I don't want an alias to launch to my application, I want an environment variable that I can use inside my application, like so

Code: Select all

string value = Environment.GetEnvironmentVariable("VAR_NAME");
Is there no way to set it?
Catalin
Posts: 7664
Joined: Wed Jun 13, 2018 7:49 am

Re: Environment Variables don't work in MSIX?

Hello Keren,

As far as I know, MSIX only supports App Execution Aliases, which are quite similar to env variables but can only be used for your application.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”