wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace AsiaINFO.SMS.APPCMPP2
{
    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Permissions;
 
    public class SetEnv
    {
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern bool SetEnvironmentVariable(string lpName, string lpValue);
        public static bool SetEnvironmentVariableEx(string environmentVariable, string variableValue)
        {
            try
            {
                new EnvironmentPermission(EnvironmentPermissionAccess.Write, environmentVariable).Demand();
                return SetEnvironmentVariable(environmentVariable, variableValue);
            }
            catch (SecurityException exception)
            {
                Console.WriteLine("Exception:" + exception.Message);
            }
            return false;
        }
    }
}