-
Notifications
You must be signed in to change notification settings - Fork 3
Fixup: EnvVarFixup
The EnvVarFixup allows an MSIX package to contain settings for environment variables.
MSIX provides no support to add to modify environment variables at this time. This fixup allows the app to specify new environment variables not present on the target system, or override those on the system. Unlike standard environment variables that may be per-system or per-user, these variables are implemented on a per-package basis by the fixup. Additionally, these environment variables may be designated to be read-write or read-only depending on whether the application wants to allow the user to also be able modify them from within the application at runtime.
The EnVarFixup intercepts the Windows API 'GetEnvironmentVariable' and consults the list of package environment variables defined in the config.json
file configuration for this fixup.
Applications calling this Windows API are supported by information about system and user environment variables that are contained in a portion of kernel memory knows as the 'Process Block'. The environment variables defined there come from the parent process and ultimately the HKLM or HKCU based registrations in the Windows Registry. Although the MSIX package may contain additional registry entries in the container registry for this package, these are not used by MSIX.
The configuration for this fixup allows you to define an array of environment variable name
, value
, and useRegistry
triplets. Depending on how the boolean field useRegistry
is set:
- If set to
true
, the intercept will first try to obtain the setting from the Container registry, then if not found the system registry, then if not found thevalue
field of this entry. If found in either registry under an HKCU key, the value may be modifiable by the application at runtime. If found under an HKLM key in the container registry this item is not modifiable at runtime, but if found in the system registry it is only modifiable if the application has elevated permissions to write to HKLM. If the fallback entry in the 'value' field is used, the application may not alter the value at runtime. - If set to
false
, thevalue
field of the configuration is used without consulting the registry and this value may not be modified by the application at runtime.
Note that the name
field of the configuration is a regex string, allowing you to specify an exact name or to use regex style syntax.
As few applications alter environment variables at runtime, the most common cases are to either define the exact name for environment variable in this json directly (with useregistry
set to false) or if the registry based registration is in the container registry file (registry.dat) to set useregistry
to true.
Below is an example of the configuration for this element:
"config": {
"EnvVars": [
{
"name" : "Var1Name",
"value" : "SpecifiedValue1",
"useregistry": "false"
},
{
"name" : "Var2Name",
"value" : "BackupValue2",
"useregistry": "true"
}
,
{
"name" : "MyName.\*",
"value" : "",
"useregistry": "true"
}
]
}
Additional documentation on this fixup is available in the Developer documentation page.