获取Revit安装版本信息及安装路径

通过Revit卸载注册表信息。注册表路径如下:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Autodesk Revit 版本信息

获取Revit安装版本信息及安装路径_第1张图片

 

撸下代码吧。

        /// 
        /// 获取某个版本安装路径
        /// 
        /// 
        /// 
        public static string GetIntallPathInfo(string Version)
        {
            try
            {
                string ExeName = "Revit.exe";
                string SubKeyName = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
                string SoftName = string.Format("Autodesk Revit {0}", Version);
                //Registry.LocalMachine
                using (RegistryKey RegistryKey1 = Registry.LocalMachine.OpenSubKey(SubKeyName, false))
                {
                    if (RegistryKey1 == null)
                    {
                        return string.Empty;
                    }
                    if (RegistryKey1.GetSubKeyNames() == null)
                    {
                        return string.Empty;
                    }

                    RegistryKey RegistryKey2 = RegistryKey1.OpenSubKey(SoftName, false);
                    if (RegistryKey2 == null)
                    {
                        return string.Empty;
                    }

                    //获取软件名
                    string SoftwareName = RegistryKey2.GetValue("DisplayName", "").ToString();
                    //安装地址信息
                    string InstallLocation = RegistryKey2.GetValue("InstallLocation", "").ToString();

                    return System.IO.Path.Combine(InstallLocation, ExeName);
                }
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

 

你可能感兴趣的:(Revit二次开发)