The
Environment.SetEnvironmentVariable[
^] method provides three targets via the
EnvironmentVariableTarget
parameter:
Process
- the variable only applies to the current process;User
- the variable is stored in the registry for the current user, and persists across reboots;Machine
- the variable is stored in the registry for the entire computer (requires elevation), and persists across reboots;
None of those options look suitable for what you're trying to achieve.
Since you're just setting the variable to an eight-digit number, which would fit within a 32-bit integer, why not simply return the value from your program, and use the batch file to set the variable?
static class Program
{
static int Main()
{
DateTime theDate = DoSomeFunkyCalculations();
int result = (10000 * theDate.Year) + (100 * theDate.Month) + theDate.Day;
return result;
}
}
YourProgram.exe
SET date = %errorlevel%
...