Problem: System %PATH% variable is colliding with other FlexApps when using Scripts to add/remove the new path entries per FlexApp.
In the past on some older ProfileUnity versions, customers used post-activation scripts like this to set %PATH% settings for a FlexApp:
Post-Activation Script - AddPathEnv.bat
powershell.exe -ExecutionPolicy ByPass -File "C:\Program Files\Common Files\AddpathENV.ps1"
This then executes the PowerShell 5 script "C:\Program Files\Common Files\AddpathENV.ps1" upon activation, which contains:
[Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";C:\Program Files\Common Files\Tom Sawyer Software\10.0.0" , [EnvironmentVariableTarget]::Machine)
This script appends the original System %PATH% Environment variable with this directory:
"C:\Program Files\Common Files\Tom Sawyer Software\10.0.0"
When using multiple FlexApps using this same type of scripting method, you will eventually run into the issue where one "Overrides" the other, and one FlexApp or the other may fail to work properly because its path entry is "missing".
Example Application used here:
Idera ERStudio Data Architect - Needs "C:\Program Files\Common Files\Tom Sawyer Software\10.0.0" in the %PATH% Env Variable.
The correct way to get %PATH% Variables to always work in FlexApps:
Option 1:
1. Once you know the actual path that the application needs, Edit the package in the FPC console, and then check to see if the following registry setting exists inside the FPC Package editor:
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment
(If HKLM has no SYSTEM Key at all, go to Option 2 below, as the FPC Editor is restricted from adding new keys under HKLM, unlike HKCU).
If HKLM\SYSTEM exists already, but not ControlSet001\Control\Session Manager\Environment, simply re-create the structure in the FPC Package Editor (Edit Package Button) using New Keys, and add a new Entry:
Type: REG_EXPAND_SZ
Name: Path
Data: C:\Program Files\Common Files\Tom Sawyer Software\10.0.0
Save the Package. Test and check %PATH% environment variables. FYI - Option 2 is not necessary, this should be complete.
Option 2:
If you do not have HKLM\SYSTEM already saved in your package, you cannot add it manually - You will need to add the path to the same REG value using Regedit on the FPC:
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment:
Double-click the "Path" REG_EXPAND_SZ Value and copy paste the whole string to Notepad. Leave notepad open for later to put this value back. After saving the values to Notepad, remove the entire line.
Add/Paste only the new %SYSTEM% path you want to add into your FlexApp package, and click OK:
Now, on the left-hand side, select Environment. Right-Click & choose Export. Save the file to your reg file export to your FPC's desktop. (I called it simply Path.reg):
Once complete, you will want to replace the original value from Notepad back into the Path value using REGEDIT to put it back the way it was originally.
Open the exported Path.reg file with Notepad. Since we exported the entire branch, remove Everything BUT the Path entry (Because it's Type "REG_EXPAND_SZ", the Path value is in hexadecimal).
Save the file after removing everything but Path, so it looks like this:
Edit the FlexApp again. Click On "Registry" in the left side navigation. Then choose "Import" at the top. Select the Path.reg you created.
Browse to your desktop path.reg file, browse to c:\users\<yourusername>\desktop, select it, and import it:
Now you should see your %PATH% environment variable you just imported.
4. Save the package. Test and check the environment variables on playback/activation using a CMD.exe prompt and typing set (This will show all the Env variables - search for PATH in the list and check it for the new PATH entry you added above).
Notes: The System %PATH% Variable is never "layered" with the FlexApp; Instead, the contents of it are actually merged with the System's current %PATH% content upon activation. This variable is unique that way. Also, it applies only to SYSTEM %PATH% variables.
User %PATH% Variables: If you are trying to set a USER %PATH% variable, you will need to use pre/post Activation scripts, like the first examples.
References: What are PATH and other environment variables, and how can I set or use them? - Super User
Product: FlexApp
Product Version: 6.8.4+
Expires: 365 days from publishing.
Updated: March 19, 2024