joepage

Check: Framework version & Adobe Installed

May 13th, 2022
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.73 KB | None | 0 0
  1.         private void CheckFramework()
  2.         {
  3.             int releaseKey = CUtils.GetDotNetVersionFromRegistry();
  4.             string releaseText = CUtils.GetDotNetVersionString(releaseKey);
  5.             CLog.WriterFormatLog(PathLogBase, $"Net Framework installed: {releaseText} ({releaseKey})", EtypeLog.Info);
  6.             if (releaseKey < CUtils.VERSION_46)
  7.             {
  8.                 MessageBox.Show("Su questa postazione non risulta installato il NET Framework versione 4.6 o successive, necessari per una ottimale navigabilitĂ  dei siti Web. Per l’aggiornamento del NET Framework, si consiglia di contattare il centro specializzato.", "ATTENZIONE:");
  9.             }
  10.         }
  11.  
  12.  
  13.  
  14.         internal static int GetDotNetVersionFromRegistry()
  15.         {
  16.             int releaseKey = 0;
  17.             using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
  18.             {
  19.                 releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
  20.             }
  21.             return releaseKey;
  22.         }
  23.  
  24.         internal static string GetDotNetVersionString(int releaseKey)
  25.         {
  26.             if (releaseKey >= VERSION_48)
  27.             {
  28.                 return "4.8 or later";
  29.             }
  30.             if (releaseKey >= VERSION_472)
  31.             {
  32.                 return "4.7.2 or later";
  33.             }
  34.             if (releaseKey >= VERSION_471)
  35.             {
  36.                 return "4.7.1 or later";
  37.             }
  38.             if (releaseKey >= VERSION_47)
  39.             {
  40.                 return "4.7 or later";
  41.             }
  42.             if (releaseKey >= VERSION_462)
  43.             {
  44.                 return "4.6.2 or later";
  45.             }
  46.             if (releaseKey >= VERSION_461)
  47.             {
  48.                 return "4.6.1 or later";
  49.             }
  50.             if (releaseKey >= VERSION_46)
  51.             {
  52.                 return "4.6 or later";
  53.             }
  54.             if (releaseKey >= VERSION_46RC)
  55.             {
  56.                 return "4.6 RC or later";
  57.             }
  58.             if ((releaseKey >= VERSION_452))
  59.             {
  60.                 return "4.5.2 or later";
  61.             }
  62.             if ((releaseKey >= VERSION_451))
  63.             {
  64.                 return "4.5.1 or later";
  65.             }
  66.             if ((releaseKey >= VERSION_45))
  67.             {
  68.                 return "4.5 or later";
  69.             }
  70.             // This line should never execute. A non-null release key should mean
  71.             // that 4.5 or later is installed.
  72.             return "No 4.5 or later version detected";
  73.         }
  74.  
  75.         internal static bool AdobeInstalled(out string pPath)
  76.         {
  77.             pPath = string.Empty;
  78.             string sKey = string.Empty;
  79.             bool bInstalled = false;
  80.  
  81.             RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
  82.             if (adobe == null)
  83.             {
  84.                 var policies = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Policies");
  85.                 if (policies != null)
  86.                     adobe = policies.OpenSubKey("Adobe");
  87.             }
  88.             if (adobe != null)
  89.             {
  90.                 RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
  91.                 if (acroRead != null)
  92.                 {
  93.                     try
  94.                     {
  95.                         string[] acroReadVersions = acroRead.GetSubKeyNames();
  96.                         sKey = adobe.OpenSubKey("Acrobat Reader").OpenSubKey(acroReadVersions[0]).OpenSubKey("InstallPath").ToString();
  97.                         pPath = Convert.ToString(Registry.GetValue(sKey, "", ""));
  98.                         bInstalled = !string.IsNullOrEmpty(pPath);
  99.                     }
  100.                     catch (Exception exc)
  101.                     {
  102.                     }
  103.                 }
  104.                 else
  105.                 {
  106.                     acroRead = adobe.OpenSubKey("Adobe Acrobat"); // acrobat dc reader 2022
  107.                     if (acroRead != null)
  108.                     {
  109.                         try
  110.                         {
  111.                             string[] acroReadVersions = acroRead.GetSubKeyNames();
  112.                             sKey = adobe.OpenSubKey("Adobe Acrobat").OpenSubKey(acroReadVersions[0]).OpenSubKey("InstallPath").ToString();
  113.                             pPath = Convert.ToString(Registry.GetValue(sKey, "", ""));
  114.                             bInstalled = !string.IsNullOrEmpty(pPath);
  115.                         }
  116.                         catch (Exception exc)
  117.                         {
  118.                         }
  119.                     }
  120.                 }
  121.             }
  122.             return bInstalled;
  123.         }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment