Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save UweKeim/5678585 to your computer and use it in GitHub Desktop.
Save UweKeim/5678585 to your computer and use it in GitHub Desktop.
Checks whether Microsoft Outlook is installed on a Windows system.
private bool IsOutlookInstalled()
{
Type requestType = Type.GetTypeFromProgID("Outlook.Application", false);
if (requestType == null)
{
RegistryKey key = null;
try
{
key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office", false);
if (key != null)
{
double version = 0.0, temp = 0.0;
string[] valueNames = key.GetSubKeyNames();
for (int i = 0; i < valueNames.Length; i++)
{
temp = 0.0;
try
{
temp = Convert.ToDouble(valueNames[i],
CultureInfo.CreateSpecificCulture("en-US").NumberFormat);
}
catch
{
}
if (temp > version) version = temp;
}
key.Close();
if (version != 0.0)
requestType = Type.GetTypeFromProgID("Outlook.Application." + version.ToString().Replace(",", "."), false);
}
}
catch
{
if (key != null) key.Close();
}
}
return (requestType != null);
}
private int GetOfficeVersion()
{
RegistryKey key = null;
try
{
key = Registry.ClassesRoot.OpenSubKey("Outlook.Application\\CurVer", false);
if (key != null)
{
string version = key.GetValue("", "Outlook.Application.9").ToString(); key.Close();
int pos = version.LastIndexOf(".");
if (pos >= 0)
{
version = version.Remove(0, pos + 1);
return Convert.ToInt32(version);
}
}
}
catch (Exception e)
{
if (key != null) key.Close();
module.DoError(e);
}
return 9;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment