Menu

[r677]: / trunk / GoogleContactsSync / OutlookRegistryUtils.cs  Maximize  Restore  History

Download this file

162 lines (147 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace GoContactSyncMod
{
internal static class OutlookRegistryUtils
{
public static string GetPossibleErrorDiagnosis()
{
int outlookVersion = GetMajorVersion(GetOutlookPath());
string diagnosis = CheckOfficeRegistry(outlookVersion);
return "Could not connect to 'Microsoft Outlook'.\r\nYou have " + GetMajorVersionToString(outlookVersion) + " installed.\r\n" + diagnosis;
}
private static string CheckOfficeRegistry(int outlookVersion)
{
string toReturn = string.Empty;
string registryVersion = ConvertMajorVersionToRegistryVersion(outlookVersion);
const string interfaceVersion = @"Interface\{00063001-0000-0000-C000-000000000046}\TypeLib";
RegistryKey interfaceKey = Registry.ClassesRoot.OpenSubKey(interfaceVersion, false);
if (interfaceKey != null)
{
String typeLib = interfaceKey.GetValue(string.Empty).ToString();
if (typeLib != "{00062FFF-0000-0000-C000-000000000046}")
return "Your registry " + interfaceKey.ToString() + " points to TypeLib " + typeLib + " and should to {00062FFF-0000-0000-C000-000000000046}" + registryVersion + ".\r\nPlease read FAQ and fix your Office installation";
String version = interfaceKey.GetValue("Version").ToString();
if (version != registryVersion)
return "Your registry " + interfaceKey.ToString() + " points to version " + version + " and your Outlook is installed with version " + registryVersion + ".\r\nPlease read FAQ and fix your Office installation";
}
else
{
return "Cannot open registry " + interfaceKey.ToString() + ".\r\nPlease read FAQ and fix your Office installation";
}
if (!string.IsNullOrEmpty(registryVersion))
{
string RegKey = @"TypeLib\{00062FFF-0000-0000-C000-000000000046}\" + registryVersion + @"\0\";
RegistryKey mainKey = Registry.ClassesRoot.OpenSubKey(RegKey + "win32", false);
if (mainKey != null)
{
String path = mainKey.GetValue(string.Empty).ToString();
if (!File.Exists(path))
return "Your registry " + mainKey.ToString() + " points to file " + path + " and this file does not exist.\r\nPlease read FAQ and fix your Office installation";
}
mainKey = Registry.ClassesRoot.OpenSubKey(RegKey + "win64", false);
if (mainKey != null)
{
String path = mainKey.GetValue(string.Empty).ToString();
if (!File.Exists(path))
return "Your registry " + mainKey.ToString() + " points to file " + path + " and this file does not exist.\r\nPlease read FAQ and fix your Office installation";
}
mainKey = Registry.ClassesRoot.OpenSubKey(@"TypeLib\{00062FFF-0000-0000-C000-000000000046}\", false);
String[] keys = mainKey.GetSubKeyNames();
if (keys.Length > 1)
{
string allKeys = "";
for (int i = 0; i < keys.Length; i++)
{
string element = keys[i];
if (element != registryVersion)
{
allKeys = allKeys + element + ",";
}
}
allKeys = allKeys.Substring(0, allKeys.Length - 1);
return "Your registry " + mainKey.ToString() + " points to Office versions: " + allKeys + " other than you have installed: " + registryVersion + ".\r\nPlease read FAQ and fix your Office installation";
}
}
return toReturn;
}
private static string GetOutlookPath()
{
const string regKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths\outlook.exe";
string toReturn = string.Empty;
try
{
RegistryKey mainKey = Registry.CurrentUser.OpenSubKey(regKey, false);
if (mainKey != null)
{
toReturn = mainKey.GetValue(string.Empty).ToString();
}
}
catch
{ }
if (string.IsNullOrEmpty(toReturn))
{
try
{
RegistryKey mainKey = Registry.LocalMachine.OpenSubKey(regKey, false);
if (mainKey != null)
{
toReturn = mainKey.GetValue(string.Empty).ToString();
}
}
catch
{ }
}
return toReturn;
}
private static int GetMajorVersion(string path)
{
int toReturn = 0;
if (File.Exists(path))
{
try
{
toReturn = FileVersionInfo.GetVersionInfo(path).FileMajorPart;
}
catch
{ }
}
return toReturn;
}
private static string ConvertMajorVersionToRegistryVersion(int version)
{
switch (version)
{
case 9: return "9.0";
case 10: return "9.1";
case 11: return "9.2";
case 12: return "9.3";
case 14: return "9.4";
case 15: return "9.5";
case 16: return "9.6";
default: return string.Empty;
}
}
private static string GetMajorVersionToString(int version)
{
switch (version)
{
case 7: return "Office 97";
case 8: return "Office 98";
case 9: return "Office 2000";
case 10: return "Office XP";
case 11: return "Office 2003";
case 12: return "Office 2007";
case 14: return "Office 2010";
case 15: return "Office 2013";
case 16: return "Office 2016";
default: return "unknown Office version (" + version + ")";
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.