日期:2014-05-17  浏览次数:20834 次

C# 设置环境变量值
一些是C# 中用程序来设置系统环境变量值:

RegistryKey regLocalMachine = Registry.LocalMachine;
            RegistryKey regSYSTEM = regLocalMachine.OpenSubKey("SYSTEM", true);//打开HKEY_LOCAL_MACHINE下的SYSTEM
            RegistryKey regControlSet001 = regSYSTEM.OpenSubKey("ControlSet001", true);//打开ControlSet001
            RegistryKey regControl = regControlSet001.OpenSubKey("Control", true);//打开Control
            RegistryKey regManager = regControl.OpenSubKey("Session Manager", true);//打开Control 
            RegistryKey regEnvironment = regManager.OpenSubKey("Environment", true);//打开MSSQLServer下的MSSQLServer
            regEnvironment.SetValue("path", env_path);//读取path的值

应用 的程序集为:
using Microsoft.Win32;//注册表操作要引用的空间
using System.Runtime.InteropServices;//调用API函数需要的引用,来加载非托管类user32.dll