Advertisement
uwekeim

Check whether Outlook is installed via C#

Jun 28th, 2012
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. private bool IsOutlookInstalled()
  2. {
  3.     Type requestType = Type.GetTypeFromProgID("Outlook.Application", false);
  4.     if (requestType == null)
  5.     {
  6.         RegistryKey key = null;
  7.         try
  8.         {
  9.             key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office", false);
  10.             if (key != null)
  11.             {
  12.                 double version = 0.0, temp = 0.0;
  13.                 string[] valueNames = key.GetSubKeyNames();
  14.                 for (int i = 0; i < valueNames.Length; i++)
  15.                 {
  16.                     temp = 0.0;
  17.                     try
  18.                     {
  19.                         temp = Convert.ToDouble(valueNames[i],
  20.                         CultureInfo.CreateSpecificCulture("en-US").NumberFormat);
  21.                     }
  22.                     catch
  23.                     {
  24.                     }
  25.                     if (temp > version) version = temp;
  26.                 }
  27.                 key.Close();
  28.                 if (version != 0.0)
  29.                     requestType = Type.GetTypeFromProgID("Outlook.Application." + version.ToString().Replace(",", "."), false);
  30.             }
  31.         }
  32.         catch
  33.         {
  34.             if (key != null) key.Close();
  35.         }
  36.     }
  37.     return (requestType != null);
  38. }
  39.  
  40. private int GetOfficeVersion()
  41. {
  42.     RegistryKey key = null;
  43.     try
  44.     {
  45.         key = Registry.ClassesRoot.OpenSubKey("Outlook.Application\\CurVer", false);
  46.         if (key != null)
  47.         {
  48.             string version = key.GetValue("", "Outlook.Application.9").ToString(); key.Close();
  49.             int pos = version.LastIndexOf(".");
  50.             if (pos >= 0)
  51.             {
  52.                 version = version.Remove(0, pos + 1);
  53.                 return Convert.ToInt32(version);
  54.             }
  55.         }
  56.     }
  57.     catch (Exception e)
  58.     {
  59.         if (key != null) key.Close();
  60.         module.DoError(e);
  61.     }
  62.     return 9;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement