Set environment variables for a process

后端 未结 2 738
时光取名叫无心
时光取名叫无心 2020-11-30 03:31

What is the environment variable concept?

In a C# program I need to call an executable. The executable will call some other executables that reside in the same folde

2条回答
  •  天涯浪人
    2020-11-30 04:16

    There are many types of environment variables, like system level and users. It depends on your requirements.

    For setting environment variables, just use the Get Set method. Pass variables Name and Value as parameters and if use to define access level then must pass with it. For accessing the value then use the Set method to pass the access level parameter too.

    For example, I am defining user-level variables:

    //For setting and defining variables
    System.Environment.SetEnvironmentVariable("PathDB", txtPathSave.Text, EnvironmentVariableTarget.User);
    System.Environment.SetEnvironmentVariable("DBname", comboBoxDataBaseName.Text, EnvironmentVariableTarget.User);
    
    //For getting
    string Pathsave = System.Environment.GetEnvironmentVariable("PathDB", EnvironmentVariableTarget.User);
    string DBselect = System.Environment.GetEnvironmentVariable("DBname", EnvironmentVariableTarget.User);
    

提交回复
热议问题