C# 检测Office版本+;友好的名字
我正在尝试以友好的格式获取Outlook的运行版本,以及该版本是64位还是32位。到目前为止:C# 检测Office版本+;友好的名字,c#,outlook,C#,Outlook,我正在尝试以友好的格式获取Outlook的运行版本,以及该版本是64位还是32位。到目前为止: Writeline(Current version: + new Microsoft.Office.Interop.Outlook.Application().Version;); // Current version: 15.0.0.5031 任何提示?您可以使用注册表确定Outlook是32位还是64位: static bool IsOutlook64Bit() { using (Reg
Writeline(Current version: + new Microsoft.Office.Interop.Outlook.Application().Version;);
// Current version: 15.0.0.5031
任何提示?您可以使用注册表确定Outlook是32位还是64位:
static bool IsOutlook64Bit() {
using (RegistryKey officeKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Office")) {
if (officeKey != null) {
Regex versionExp = new Regex(@"^[1-9][0-9]*\.[0-9]+$");
string maxVersion = officeKey.GetSubKeyNames()
.Where(x => versionExp.IsMatch(x))
.OrderByDescending(x => Decimal.Parse(x))
.FirstOrDefault();
if (!String.IsNullOrEmpty(maxVersion)) {
using (RegistryKey key = officeKey.OpenSubKey(maxVersion + @"\Outlook")) {
if (key != null) {
string bitness = Convert.ToString(key.GetValue("Bitness", null));
return bitness.Equals("x64", StringComparison.OrdinalIgnoreCase);
}
}
}
}
}
throw new InvalidOperationException("Outlook not found on this machine.");
}
注意:上述方法使用最新版本,可能不是正在运行的版本-但是,在大多数情况下,这是正确的。Microsoft不建议安装任何Office产品的多个版本。为了100%准确,您可以解析问题中包含的版本号字符串,并匹配主要和次要组件(例如,16.0
),而不是只取最大值
友好名称(例如Outlook 2016)无法通过对象模型获得,我也不相信它可以在注册表中轻松查询。可能更容易将版本号的主要部分与已知值列表进行匹配;e、 g
int major = (int)Decimal.Parse(maxVersion);
switch (major) {
case 12:
return "Outlook 2007";
case 14:
return "Outlook 2010";
case 15:
return "Outlook 2013";
case 16:
return "Outlook 2016":
}
据我所知,获得一个友好的名称并没有什么好处,您需要检查版本号。就像布拉德利的解决方案一样,获得Outlook的最大版本。因此,我认为您可以继续编写代码并复制Bradley的代码以检查Outlook版本。如下所示:
var version = new Microsoft.Office.Interop.Outlook.Application().Version.Substring(0,2);
int major = (int)Decimal.Parse(version);
switch (major)
{
case 12:
return "Outlook 2007";
case 14:
return "Outlook 2010";
case 15:
return "Outlook 2013";
case 16:
return "Outlook 2016";
}
尝试其他属性,如Name/ProductCode等,如下所示:很好的尝试,但没有运气Name=Outlook/ProductCode={GUID}