入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

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

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

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像