In einem unserer Programme habe ich ein Microsoft-Office-Outlook-Add-in geschrieben (mithilfe von AddInExpress).
Im Vorfeld war dafür eine Prüfung notwendig, ob Outlook überhaupt installiert ist. Nachfolgender Code erledigt dies:
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;
}