System.Environment.SetEnvironmentVariableCore C# (CSharp) Method

SetEnvironmentVariableCore() private static method

private static SetEnvironmentVariableCore ( string variable, string value ) : void
variable string
value string
return void
        private static void SetEnvironmentVariableCore(string variable, string value)
        {
            if (!Interop.Kernel32.SetEnvironmentVariableW(variable, value))
            {
                int errorCode = Marshal.GetLastWin32Error();
                switch (errorCode)
                {
                    case Interop.Errors.ERROR_ENVVAR_NOT_FOUND: // Allow user to try to clear a environment variable
                        return;
                    case Interop.Errors.ERROR_FILENAME_EXCED_RANGE: // Fix inaccurate error code from Win32
                        throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(value));
                    default:
                        throw new ArgumentException(Interop.Kernel32.GetMessage(errorCode));
                }
            }
        }

Same methods

Environment::SetEnvironmentVariableCore ( string variable, string value, EnvironmentVariableTarget target ) : void