Windows: Set Environment variables for users
This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.For some cases you might need to set environment variables for your .NET application.This is true to .NET core too, when you are storing your application settings in these variables. How to set up a script for the job It’s handy to create a windows command line script for creating these variables, because when you are on a new work environment, than you don’t need to look up the keys and values. So bring up your most-loved text editor, make your environment_variable_creator.bat, and add the following code: If you are using .NET core’s configuration builder with a prefix like this: Then you need to set your variables with prefix “PREFIX_” in the bat file. In this scenario, VARIABLE1 can not be read, because it does not contain the prefix. The code sets the variables only for your user account, not for others. You can parameterize the SETX command to set the settings for a different user, but i recommend, to run the script with a command line for the targeted user, because its much easier. To run your script under other users name, then open your command prompt with ‘Run as… different user’
Hi, I am András,
I am a seasoned software engineer from Budapest, Hungary with a strong focus on mobile app development using .NET MAUI and Xamarin.Forms. My expertise also extends to website building for my happy customers and other complex system designing. I am passionate about developing well-organized, maintainable software solutions.