Environment Variable in MSIX Using PSF

Copper Contributor

Hello Members!

 

I have been working on and around on the Environment Variables Fixup in the MSIX but unfortunately neither I am getting any error in my config.json file nor I am able to see the variables inside the virtual container.

 

Please see the below config.json file:

 

{
  "applications": [
    {
      "id": "SevenZFM",
      "executable": "VFS\\ProgramFilesX64\\7-Zip\\7zFM.exe",
      "arguments": "",
      "workingDirectory": ""
    }
  ],
  "processes": [
    {
      "executable": "PSFSample",
      "fixups": [
        {
          "dll": "EnvVarFixup32.dll",
          "config": {
            "envVars": [
"name" : "Z",
            "value" : "C:\temp",
            "useregistry": "false"
]
          }
        }
      ]
    }
  ]
}
 
 
I would be very grateful if someone could help me out in this. @TIMOTHY MANGAN 
 
Thanks in Advance
9 Replies

@Abhi211 You didn't specify the source of the PSF being used.  Sometimes that matters, but probably not in this case.  Here is what is obvious from the post:

 

In the json, the name of the fixup file should not include the bitness (architecture).  It should just be listed as "EnvVarFixup.dll".  The PsfRuntime will look at the bitness of the application (x64 in your example) and then try to load a file with that added in (EnvVarFixup64.dll).  Since you made the json by hand, I'm guessing that you may have put in the files by hand, so make sure that version of the dll is in the package (it never hurts to put both bitnesses in when you don't know the app).

Ensure the correctness of your config.json file for MSIX environment variable fixup by correcting the syntax in the "envVars" section. Each environment variable should be enclosed in curly braces and the path in the "value" field should use double backslashes. For example: json "config": { "envVars": [ { "name": "Z", "value": "C:\\temp", "useregistry": "false" } ] } Make sure the "EnvVarFixup32.dll" is correctly placed in the package and is compatible with your system architecture. After making these adjustments, rebuild and repackage your MSIX application. This should enable the specified environment variable within the virtual container.

@Abhi211 

In your example the executable is not defined correctly and the slashes are not escaped in the variable value. Here is an example that should work, but remember to add EnvVarFixup64.dll as @TIMOTHY MANGAN mentioned, but keep the json the same - "dll": "EnvVarFixup.dll"

{
  "applications": [
    {
      "id": "SevenZFM",
      "executable": "VFS\\ProgramFilesX64\\7-Zip\\7zFM.exe",
      "arguments": "",
      "workingDirectory": ""
    }
  ],
  "processes": [
    {
      "executable": ".*",
      "fixups": [
        {
          "dll": "EnvVarFixup.dll",
          "config": {
            "envVars": [
              {
                "name": "Z",
                "useregistry": "false",
                "value": "C:\\temp"
              }
            ]
          }
        }
      ]
    }
  ]
}

 

@TIMOTHY MANGAN 

I am using your version of psf  from here "MSIX-PackageSupportFramework/ZipRelease-v2023.08.13 at develop · TimMangan/MSIX-PackageSupportFramew..."...

About the bitness I tried without giving it, but it didn't work. Do you think I am missing on something else?

 

These are the files I have included.

Abhi211_0-1704211966457.png

Even the manifest seems fine to me..

Abhi211_1-1704212070538.png

 

@Edijs_Perkums_MasterPackager 

Thank you for your response!

As you suggested I changed my config json accordingly, but I can't find the variable.

 

See the below json file.

Abhi211_0-1704213023902.png

 

 

@Abhi211 How are you checking for the variable? You will not see it in process explorer or CMD. The only way I was able to actually verify that the fixup works was by writing my own C# console program that displays the value of the environment variable.

@Edijs_Perkums_MasterPackager  

I am using Invoke-CommandInDesktopPackage -PackageFamilyName "7Zip_8h66172c634n0" -command "cmd.exe" -AppId "SevenZFM" -PreventBreakaway to check the variable inside the bubble. Using the SET command in the cmd inside the bubble.

 

Will this not work?

No, it may be the app is fine and your test is leading you astray!

 

The Invoke-CommandInDesktopPackage, in general, is OK to get into the environment, but as you are not starting a PsfLauncher, the PSF is not injected into your cmd process, so the fixup is unavailable to your test..

 

The best thing I would recommend to troubleshoot is to add the Debug version of the PSF, and run the application (causing it to read the value of the environment variable), and using the SysInternals tool DebugView to capture debug output.  Of interest in the output is the launch of the primary app by PsfLauncher (checking that the fixup dll is successfully loaded into the process and that it doesn't complain about a bad config.json file), and then when GetEnvironmentVariable is called by the app.

@TIMOTHY MANGAN 

Even I guess the same.

I will go through the steps you told and let you know if it works!

 

Thank You!!