using System; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; using Microsoft.Win32; namespace EnvironmentTest { class Program { static void Main(string[] args) { IDictionary envir = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine); ICollection col = envir.Values; foreach (String str in col) { Console.WriteLine(str); Console.Read(); } //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 //Console.WriteLine(regEnvironment.GetValue("path").ToString()); //Console.Read(); } } }
如上代码,可以读取系统环境变量,但是%Java_Home%都经过转义了,如何让其不经过转义原样输出?