Windows Environment variables in ModelBuilder

07-15-2020 09:54 AM
Status: Open
Labels (1)
MVP Esteemed Contributor

It sure would be great to access Windows environment variables in ModelBuilder as builtin model variables. For example %COMPUTERNAME% %USERNAME% or user defined ones set in the Windows Control Panel or in a startup script. I realize one can do this with Calculate Value calling os.environ["COMPUTERNAME"], but this would be easier.

Way back in the 20th century, in ArcInfo Workstation AML, we could access windows env variables like AML variables with %COMPUTERNAME%. In that environment, if a windows environment variable conflicted with an AML variable the model variable would always take precedence to avoid confusion. I think that would be a good way to do it in ModelBuilder too.

A very common use case for me is constructing path names, so for example %TEMP%\%USERNAME%_%t%

Tags (2)

Thanks Curtis for this idea!

Please can you share a few more use cases when you would want to use these Windows environment variables in a model to construct a path instead of using environment variables or data paths directly?
User profile specific? 

Thank You!


examples of windows environment variables. 

If the variable didn't exist the expected behavior would what is is now when you specify a variable that does not exist, ie you get the literal "%VAR%" unmodified.

Path to create a folder in TEMP for the model to log information:

Create Folder, folder: %TEMP% name:%COMPUTERNAME%_%USERNAME%

Access the 1:24K quads in the ArcMap folder: MakeFeaturesLayer %AGSDESKTOPJAVA%\\Reference Systems\World Time Zones.shp  quads

Find out it ArcMap is installed: CalculateValue arcpy.Exists(r"%AGSDESKTOPJAVA%")

Find out if ArcInfo Workstation is installed (haha) CalculateValue arcpy.Exists(r"%ARCHOME%")

Write a status info table to %APPDATA%\ESRI folder TableToTable %logtable% %APPDATA%\ESRI\log%t%.dbf

If expression to find out whether we have more than two processors: %NUMBER_OF_PROCESSORS% > 2

Access user defined variable (set by user in control panel) lay, MY_LOGPATH   %MY_LOGPATH%

To get a quick list of environment variables open a windows cmd window and enter: set


It occurred to me that it's pretty easy to get these with an arcpy method, so maybe it's a matter of documenting this functionality for use with Calculate Value:

Executing (Calculate Value): CalculateValue arcpy.GetSystemEnvironment("AGSDESKTOPJAVA") # Variant
Start Time: Wednesday, November 11, 2020 8:18:36 PM
Value = C:\Program Files (x86)\ArcGIS\Desktop10.7\
Succeeded at Wednesday, November 11, 2020 8:18:36 PM (Elapsed Time: 0.00 seconds)