//
获得环境变量路径
private string GetEPath( string key)
... {
RegistryKey pregkey;
pregkey = Registry.LocalMachine.OpenSubKey(@"SYSTEMCurrentControlSetControlSession ManagerEnvironment", true);
try
...{
if (pregkey == null)
...{
MessageBox.Show("键值不存在");
}
else
...{
if (pregkey.GetValue(key) != null)
return pregkey.GetValue(key).ToString();
}
return null;
}
finally
...{
if (pregkey != null) pregkey.Close();
}
}
private string GetEPath( string key)
... {
RegistryKey pregkey;
pregkey = Registry.LocalMachine.OpenSubKey(@"SYSTEMCurrentControlSetControlSession ManagerEnvironment", true);
try
...{
if (pregkey == null)
...{
MessageBox.Show("键值不存在");
}
else
...{
if (pregkey.GetValue(key) != null)
return pregkey.GetValue(key).ToString();
}
return null;
}
finally
...{
if (pregkey != null) pregkey.Close();
}
}
调用:设置方法:
tbjava_homepath.Text = GetEPath("java_home");
tbtomcat_homepath.Text = GetEPath("tomcat_home");
SetEPath("JAVA_HOME", this.tbjava_homepath.Text);
SetEPath("TOMCAT_HOME", this.tbtomcat_homepath.Text