Reputation: 700
Is it possible to get office 2010 bitness using getBinaryType() function which is defined in kernel32.dll something like this.
[DllImport("kernel32.dll")]
static extern bool GetBinaryType(string lpApplicationName, out uint lpBinaryType);
uint type;
GetBinaryType("applicationName",out type);
I have tried using application class as stated below but sometimes it will fail.
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;
}
Is there any another way to detect office 2010 bitness?
Upvotes: 1
Views: 928
Reputation: 138960
What I would do is
1) open the following registry key:
HKEY_CLASSES_ROOT\CLSID\{00024500-0000-0000-C000-000000000046}\LocalServer
(the guid means "Excel Application")
2) extract Excel's .EXE path from the key's default value (you want to remove all command line arguments)
3) use GetBinaryType
on the path.
Upvotes: 1