检查excel 2010 bitness

是否有可能使用在kernel32.dll中定义的getBinaryType()函数来获取office 2010 bitness。

[DllImport("kernel32.dll")] static extern bool GetBinaryType(string lpApplicationName, out uint lpBinaryType); uint type; GetBinaryType("applicationName",out type); 

我曾尝试使用应用程序类如下所述,但有时它会失败。

  public static ExcelVersion GetExcelVersion(object applicationClass) { if (applicationClass == null) throw new ArgumentNullException("applicationClass"); PropertyInfo property = applicationClass.GetType().GetProperty("HinstancePtr", BindingFlags.Instance | BindingFlags.Public); if (property == null) return ExcelVersion.Excel; return (System.Runtime.InteropServices.Marshal.SizeOf(property.GetValue(applicationClass, null)) == 8) ? ExcelVersion.Excel2010_64 : ExcelVersion.Excel2010_32; } 

有没有其他办法来检测Office 2010的位数?

我会做的是

1)打开以下registry项:

 HKEY_CLASSES_ROOT\CLSID\{00024500-0000-0000-C000-000000000046}\LocalServer 

(guid的意思是“Excel应用程序”)

2)从键的默认值中提取Excel的.EXEpath(要删除所有的命令行参数)

3)在path上使用GetBinaryType