예제 #1
0
 private void InitProductInfos()
 {
     try
     {
         mListProductInfos.Clear();
         if (mInstallInfo == null)
         {
             mInstallInfo = new InstallInfo();
             //从注册表获取已经安装的产品
             for (int i = 0; i < mListProductGUIDs.Count; i++)
             {
                 string strGUID = mListProductGUIDs[i];
                 string path;
                 if (Environment.Is64BitOperatingSystem)
                 {
                     path = string.Format(
                         @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{0}", strGUID);
                 }
                 else
                 {
                     path = string.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0}", strGUID);
                 }
                 try
                 {
                     RegistryKey rootKey = Registry.LocalMachine;
                     RegistryKey umpKey  = rootKey.OpenSubKey(path);
                     if (umpKey != null)
                     {
                         InstallProduct product = new InstallProduct();
                         product.ProductGuid = strGUID;
                         product.ProductName = umpKey.GetValue("DisplayName").ToString();
                         product.DisplayName = umpKey.GetValue("DisplayName").ToString();
                         product.InstallPath = umpKey.GetValue("InstallLocation").ToString();
                         product.Version     = umpKey.GetValue("DisplayVersion").ToString();
                         mInstallInfo.ListProducts.Add(product);
                     }
                 }
                 catch (Exception ex)
                 {
                     App.WriteLog("InitProductInfos", string.Format("Get product info fail.\t{0}", ex.Message));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ShowException(ex.Message);
     }
 }
예제 #2
0
        private void LoadInstallInfo()
        {
            try
            {
                bool   is64BitOS = Environment.Is64BitOperatingSystem;
                string path;
                if (is64BitOS)
                {
                    path = string.Format(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{0}",
                                         UpdateConsts.PACKAGE_GUID_UMP);
                }
                else
                {
                    path = string.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0}",
                                         UpdateConsts.PACKAGE_GUID_UMP);
                }
                RegistryKey rootKey = Registry.LocalMachine;
                RegistryKey umpKey  = rootKey.OpenSubKey(path);
                if (umpKey != null)
                {
                    mIsInstalled            = true;
                    mUMPProduct             = new InstallProduct();
                    mUMPProduct.Package     = UpdateConsts.PACKAGE_NAME_UMP;
                    mUMPProduct.ProductGuid = UpdateConsts.PACKAGE_GUID_UMP;
                    InstallComponent installComponent = new InstallComponent();
                    installComponent.ModuleID   = 0;
                    installComponent.ModuleName = UpdateConsts.COMPONENT_NAME_UMP;
                    mUMPProduct.ListComponents.Add(installComponent);

                    string strVersion     = umpKey.GetValue("DisplayVersion").ToString();
                    string strInstallPath = umpKey.GetValue("InstallLocation").ToString();
                    mUMPProduct.Version     = strVersion;
                    mUMPProduct.InstallPath = strInstallPath;

                    WriteLog("LoadInstallInfo",
                             string.Format("Version:{0};InstallDirectory:{1}", mUMPProduct.Version,
                                           mUMPProduct.InstallPath));
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }