You can use Environment.SetEnvironmentVariable :
Environment.SetEnvironmentVariable("SomeVariable", "Some value", EnvironmentVariableTarget.User);
The last parameter defines the scope and lifetime of the variable (process, user or machine). If you want to set a variable for the machine, you will need to run it as admin.
: , , ( , , , , ).
2: , , , . , , , .net- . script , :
. :
static void Main(string[] args)
{
string outputFile = @"c:\temp\setvars.bat";
string variable = "set SomeVariable=Some value";
File.WriteAllText(outputFile, variable);
}
BAT :
call myconsoleapp.exe
call c:\temp\setvars.bat
echo %SomeVariable%