牛骨文教育服务平台(让学习变的简单)
博文笔记

C#,net设置系统环境变量路径,如java_home

创建时间:2007-10-15 投稿人: 浏览次数:1524
 //获得环境变量路径
        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

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。