通过注册表检测Office是32位还是64位
既然 Office 也提供了 64 位安装,那么您可以在注册表中的哪个位置找到安装的 Office 版本是 32 位还是 64 位?
Now that Office also comes in a 64bit install, where in the registry do you find out if the version of Office installed is 32bit or 64bit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(28)
我之前盲目地遵循了基于 MSDN 文档的答案。今天,事实证明这低于要求。在安装了 Office Home 和 Student 且不包含 Outlook 的计算机上,存在
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Outlook
,但HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Office\14.0\Outlook
不是。我现在更改了代码,首先查找“普通”非 Wow6432Node 版本。如果存在,就会使用它。如果没有,它将继续查看 Wow6432Node 版本。这是在基于 Inno Setup 的安装程序中进行检查的 - 我不知道 Inno Setup 使用哪些 API。如果您的应用程序不以相同的方式访问注册表,您可能会看到不同的结果。I've previously blindly followed the answer based on the MSDN docs. Today, this turned out to be less than required. On a machine with Office Home and Student installed, which doesn't include Outlook,
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Outlook
was present, butHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Outlook
was not. I've now changed my code to first look for the "plain" non-Wow6432Node version. If that's present, it'll be used. If not, it will continue by looking at the Wow6432Node version. This is being checked in an Inno Setup-based installer - I don't know which APIs Inno Setup uses. If your app doesn't access the registry in the same way, you might see different results.在注册表中搜索您感兴趣的 Office 组件的安装路径,例如,对于 Excel 2010,请在 SOFTWARE(Wow6432Node)\Microsoft\Office\14.0\Excel\InstallRoot 中查找。它只会存在于 32 位注册表或 64 位注册表中,而不会同时存在于两者中。
Search the registry for the install path of the office component you are interested in, e.g. for Excel 2010 look in SOFTWARE(Wow6432Node)\Microsoft\Office\14.0\Excel\InstallRoot. It will only be either in the 32-bit registry or the 64-bit registry not both.
我最初是为 Outlook 写的。对 Word 进行了一些修改,但它无法在独立安装中运行,因为该键不显示位数,只有 Outlook 可以显示位数。
另外,我编写它是为了仅支持当前版本的 Office,=>2010
我剥离了所有设置和后期处理...
I wrote this for Outlook at first. Modified it a little for Word, but it will not work on a standalone install because that key does not show the bitness, only Outlook does.
Also, I wrote it to only support current versions of Office, =>2010
I stripped all the setup and post processing...
在我的测试中,这里描述的许多方法都失败了,我认为是因为它们依赖于 Windows 注册表中的条目,而这些条目结果并不可靠,具体取决于 Office 版本、安装方式等。因此,另一种方法是不使用完全不使用注册表(好吧,严格来说,这使它不能回答所提出的问题),而是编写一个脚本来:
以下是在 VBScript 中实现的方法:
PS。这种方法比这里的其他方法运行得更慢(在我的电脑上大约 2 秒),但在不同的安装和 Office 版本中它可能会更可靠。
几个月后,我意识到可能有一种更简单的方法,尽管仍然是实例化 Excel 实例的方法。 VBScript 是:
这依赖于以下事实:当从 64 位 Windows 上的 32 位 Excel 调用时,
Application.OperatingSystem
返回Windows(32 位)NT 10.00
或至少在我的电脑上是这样。但文档中没有提到这一点。In my tests many of the approaches described here fail, I think because they rely on entries in the Windows registry that turn out to be not reliably present, depending on Office version, how it was installed etc. So a different approach is to not use the registry at all (Ok, so strictly that makes it not an answer to the question as posed), but instead write a script that:
Here's that approach implemented in VBScript:
PS. This approach runs more slowly than others here (about 2 seconds on my PC) but it might turn out to be more reliable across different installations and Office versions.
After some months, I've realised there may be a simpler approach, though still one that instantiates an Excel instance. The VBScript is:
This relies on the fact that
Application.OperatingSystem
, when called from 32-bit Excel on 64-bit Windows returnsWindows (32-bit) NT 10.00
or at least it does on my PC. But that's not mentioned in the docs.我有 win 7 64 位 + Excel 2010 32 位。
注册表为 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-002A-0000-1000-0000000FF1CE}
所以这可以告诉操作系统的位数,而不是 Office 的位数
I have win 7 64 bit + Excel 2010 32 bit.
The registry is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-002A-0000-1000-0000000FF1CE}
So this can tell bitness of OS, not bitness of Office
我在基于 InnoSetup 的脚本中找到了一种安全可靠的方法,通过使用 Win32 API 函数来了解特定应用程序是 32 位还是 64 位(在我的例子中,我需要测试 Excel)。这个函数称为 GetBinaryType(),它来自“kernel32”(尽管它有 32 位和 64 位版本的名称),并且直接查看 exe 的标头。
I've found a secure and reliable way in my InnoSetup-based script to understand whether a particular application is 32-bit or 64-bit (in my case I needed to test Excel), by using a Win32 API function. This function is called
GetBinaryType()
, it comes from `kernel32' (despite the name it comes in 32 and 64 bit flavor) and looks directly at the exe's header.这篇维基百科文章指出:
因此,如果程序安装在
C:\Program Files
下,则它是 64 位版本。如果它安装在C:\Program Files (x86)
下,则它是 32 位安装。This Wikipedia article states:
So if the program is installed under
C:\Program Files
it is a 64-bit version. If it is installed underC:\Program Files (x86)
it is a 32-bit installation.检测 Office 位数的另一种方法是找出类型库。
例如,要检测 Outlook 的位数,请编写一个 .JS 文件,如下所示:
您可以找到其他 Office 组件的 typelib id,并替换它的函数的第一行。以下是一些有趣的 ID 的简要列表:
以上所有 lib id 都是通过 Windows SDK 工具
OLE-COM Object Viewer
找到的,您可以使用它找到更多的 lib id。这种方法的好处是它适用于所有版本的 Office,并提供对您感兴趣的每个组件的控制。此外,这些键位于 HKEY_CLASSES_ROOT 中并深度集成到系统中,因此即使在沙箱环境中也不太可能无法访问它们。
Another way to detect the bitness of Office is to find out the typelib.
For example, to detect Outlook's bitness, write a .JS file as following:
You could find out other Office component's typelib id, and replace the first line of the function for it. Here is a brief list of interesting IDs:
All above lib id were found through the Windows SDK tool
OLE-COM Object Viewer
, you could find out more lib id's by using it.The benefit of this approach is that it works for all versions of office, and provides control on every single component in you interest. Furthermore, those keys are in the HKEY_CLASSES_ROOT and deeply integrated into the system, so it is highly unlikely they were not accessible even in a sandbox environment.
您不需要编写它的脚本。看看我偶然发现的这个页面:
https://social.msdn.microsoft.com/Forums/office/en-US/ 43499ae0-bcb5-4527-8edb-f5a955987b56/how-to-detect-whether-installed-ms-office-2010-is-32-or-64-bit?forum=worddev
总结一下:
第四个字段产品代码表示产品的位数。
{BRMMmmmm-PPPP-LLLL-p000-D000000FF1CE}
p000
0 表示 x86,1 表示 x64 0-1(这也适用于 MSOffice 2013)
You do not need to script it. Look at this page that I stumbled across:
https://social.msdn.microsoft.com/Forums/office/en-US/43499ae0-bcb5-4527-8edb-f5a955987b56/how-to-detect-whether-installed-ms-office-2010-is-32-or-64-bit?forum=worddev
To summarize:
The fourth field in the productcode indicates the bitness of the product.
{BRMMmmmm-PPPP-LLLL-p000-D000000FF1CE}
p000
0 for x86, 1 for x64 0-1 (This also holds true for MSOffice 2013)
我的计算机上不存在 Outlook Bitness 注册表项。
确定 Outlook Bitness 的一种方法是检查 Outlook.exe 本身并确定它是 32 位还是 64 位。
具体来说,您可以检查 [IMAGE_FILE_HEADER.Machine][1] 类型,这将返回一个指示处理器类型的值。
有关此讨论的优秀背景信息,在阅读文件的 PE 标头时,请阅读此 (过时的链接),其中指出;
IMAGE_NT_HEADERS 结构是存储 PE 文件详细信息的主要位置。它的偏移量由文件开头的 IMAGE_DOS_HEADER 中的 e_lfanew 字段给出。 IMAGE_NT_HEADER 结构实际上有两个版本,一种用于 32 位可执行文件,另一种用于 64 位版本。这些差异是如此之小,以至于出于本次讨论的目的,我将认为它们是相同的。唯一正确的、Microsoft 批准的区分两种格式的方法是通过 IMAGE_OPTIONAL_HEADER 中 Magic 字段的值(稍后描述)。
IMAGE_NT_HEADER 由三个字段组成:
typedef struct _IMAGE_NT_HEADERS {
双字签名;
IMAGE_FILE_HEADER 文件头;
IMAGE_OPTIONAL_HEADER32 可选标头;
} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
你可以获得c#代码
Magic 字段位于 IMAGE_OPTIONAL_HEADER 结构的开头,位于 _IMAGE_NT_HEADERS 开头偏移量 24 处的 2 个字节处。 32 位的值为 0x10B,64 位的值为 0x20B。
Outlook Bitness registry key does not exist on my machine.
One way to determine Outlook Bitness is by examining Outlook.exe, itself and determine if it is 32bit or 64bit.
Specifically, you can check the [IMAGE_FILE_HEADER.Machine][1] type and this will return a value indicating processor type.
For an excellent background of this discussion, on reading the PE Header of a file read this (outdated link), which states;
The IMAGE_NT_HEADERS structure is the primary location where specifics of the PE file are stored. Its offset is given by the e_lfanew field in the IMAGE_DOS_HEADER at the beginning of the file. There are actually two versions of the IMAGE_NT_HEADER structure, one for 32-bit executables and the other for 64-bit versions. The differences are so minor that I'll consider them to be the same for the purposes of this discussion. The only correct, Microsoft-approved way of differentiating between the two formats is via the value of the Magic field in the IMAGE_OPTIONAL_HEADER (described shortly).
An IMAGE_NT_HEADER is comprised of three fields:
typedef struct _IMAGE_NT_HEADERS {
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
IMAGE_OPTIONAL_HEADER32 OptionalHeader;
} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
and you can get the c# code here.
The Magic field is at the start of the IMAGE_OPTIONAL_HEADER structure, 2 bytes at offset 24 from the start of the _IMAGE_NT_HEADERS. It has values of 0x10B for 32-bit and 0x20B for 64-bit.
最简单的方法:将“关于”图标放在 Office 2016 应用程序上。 Excel 示例
1) 打开 Excel ->文件->选项->自定义功能区
2) 您将看到 2 个窗格。从 & 选择命令自定义功能区
3) 从“选择命令”中,选择所有命令
4) 从结果列表中突出显示“关于”(Excel)
5) 从“自定义功能区”中,突出显示要放置“关于”图标的任何项目(例如视图)
6)单击底部的新建组
7) 单击位于两个窗格之间的添加按钮。
完成
现在,当您单击 Excel 中的“查看”选项卡并单击“关于”时,您将看到 32 位或 64 位
Best easy way: Put the ABOUT Icon on your Office 2016 Application. Example Excel
1) Open Excel -> File -> Options -> Customize Ribbon
2) You 'll see 2 panes. Choose Commands From & Customize The Ribbon
3) From Choose Command, Select All Commands
4) From the resulting List Highlight About (Excel)
5) From the Customize The Ribbon Pain, Highlight Any Item (ex. View) where you want to put the About icon
6) Click New group at the bottom
7) Click the add button located between the two pane.
DONE
Now when you click the View Tab in excel and click about you'll see 32 bit or 64 bit
我找到了一种更简单的方法。
使用Powershell,我们可以将Excel挂钩为COM对象。
当以这种方式请求操作系统时,我们会得到奇怪的结果,
看看这里。 PC3 是我的。
我希望这对你们有用。抱歉,缺少代码;我的脚本大部分都是实用的。
编辑:
不要忘记添加代码以在检索完数据后关闭 Excel。
昨天测试此代码后,我突然打开了大量 Excel 并崩溃了。
这将确保您让用户和管理员满意(:
I've found a much easier way.
Using Powershell, we can hook Excel as a COM object.
When requesting the OperatingSystem this way, we get strange results,
have a look here. PC3 is mine.
I hope this works for you guys. Sorry for the lack of code; my scripts are mostly functional.
Edit:
Don't forget to add the code to close Excel after you're done retrieving the data.
After testing this code yesterday I had tons of Excel opening and crashing all of a sudden..
This will make sure you'll keep users and admins happy (:
如果只想知道已安装的 Office 2010 版本的位数,则在 Office 2010 的任何应用程序中,只需单击“文件”,然后单击“帮助”。将列出有关版本号的信息,旁边的括号中将是(32 位)或(64 位)。
If one wants to know only what bit number an installed version of Office 2010 is, then in any application of Office 2010, just click on File, then on Help. Information about version number will be listed, and next to that, in parentheses, will be either (32-bit) or (64-bit).
打开 Outlook 2013 >文件>办公帐号>关于展望>单击大“?关于 Outlook”按钮 >阅读弹出说明
Open Outlook 2013 > File > Office account > About Outlook > click large "? About Outlook" button > read popup description
摘自有关 64 位版本的 Office 2010:
以及同一文章中的其他位置:
From TechNet article on 64-bit editions of Office 2010:
and elsewhere in the same article:
我测试了 Otaku 的答案,即使未安装 Outlook,Outlook 位数值也会被设置,尽管引用的文章没有明确表明情况会如此。
I've tested Otaku's answer and it appears that the Outlook bitness value is set even when Outlook is not installed, even though the article referenced does not clearly indicate that this would be the case.
为了添加 vtrz 的答案,这是我为 Inno Setup 编写的一个函数:
To add to vtrz's answer, here's a function I wrote for Inno Setup:
遗憾的是,Otacku 和 @clatonh 的方法都不适用于我 - 注册表中既没有 Outlook Bitness,也没有 {90140000-0011-0000-1000-0000000FF1CE}(对于 64 位 Office,没有Outlook已安装)。
不过,我发现的唯一方法(不通过注册表)是使用 Windows API 函数检查 Office 可执行文件之一的位数 GetBinaryType(自 Windows 2000 Professional 起)。
例如,您可以检查Winword.exe的位数,该路径存储在
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe。
这是MFC代码片段:
Regret to say, but Both Otacku's and @clatonh's methods aren't working for me - neither have Outlook Bitness nor {90140000-0011-0000-1000-0000000FF1CE} in registry (for 64-bit Office without Outlook installed).
The only way I have found, though, not via the registry, is to check bitness for one of the Office executables with the use of the Windows API function GetBinaryType (since Windows 2000 Professional).
For example, you can check the bitness of Winword.exe, which path is stored under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe.
Here is the MFC code fragment:
我找到了检查办公室位数的方法。
我们可以使用此注册表项检查 Office 365 和 2016 位数:
Platform x86 for 32 bit。
64 位平台 x64。
请检查...
I found the way for checking office bitness .
We can check office 365 and 2016 bitness using this registry key:
Platform x86 for 32 bit.
Platform x64 for 64 bit.
Please check...
注意:如果在 .NET 环境中调用,查询 Outlook 应用程序的位数无法可靠地工作。
在这里,我们在可由任何应用程序调用的 DLL 中使用 GetBinaryType():
在同一台计算机上具有完全相同的 DLL 代码和完全相同的 Outlook 二进制路径(“c:/Program Files (x86)/...”)。
这意味着您可能需要使用“IMAGE_NT_HEADERS.FileHeader.Machine”条目自行测试二进制文件。
天哪,我讨厌某些 Windows API 的错误返回值(另请参阅 GetVersion() 谎言)。
Attention: querying the bitness of the Outlook Application does NOT reliably work if called in .NET environment.
Here, we use GetBinaryType() in a DLL that can be called by any application:
With exactly the same DLL code and exactly the same Outlook binary path ("c:/Program Files (x86)/...") on the same computer.
Meaning that you might need to test the binary file yourself using "IMAGE_NT_HEADERS.FileHeader.Machine" entry.
God, I hate the incorrect return values of some Windows APIs (see also GetVersion() lie).
我发现了这种方法:
如果 HKLM\Software\WOW6432Node 存在,那么 Windows 是 64 位的。
如果 HKLM\Software\WOW6432Node\Microsoft\Office 存在,则 Office 是 32 位。
如果 HKLM\Software\WOW6432Node\Microsoft\Office 不存在,但 HKLM\Software\Microsoft\Office 存在,则 Office 是 64 位。
如果 HKLM\Software\WOW6432Node 不存在,则 Windows 和 Office 是 32 位。
来源:Technet 论坛
I found this approach:
If HKLM\Software\WOW6432Node exists then Windows is 64-bit.
If HKLM\Software\WOW6432Node\Microsoft\Office exists, then Office is 32-bit.
If HKLM\Software\WOW6432Node\Microsoft\Office does not exist, but HKLM\Software\Microsoft\Office does exist, then Office is 64-bit.
If HKLM\Software\WOW6432Node does not exist, then Windows and Office are 32-bit.
Source: Technet Forums
以下是我能够在 VBscript 中使用的内容来检测 Office 64 位 Outlook:
Here's what I was able to use in a VBscript to detect Office 64bit Outlook:
您可以在注册表中搜索 {90140000-0011-0000-0000-0000000FF1CE}。如果粗体数字以 0 开头,则为 x86,1 为 x64
对于我来说,它是
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-0057-0000-0000-0000000FF1CE}
源
You can search the registry for {90140000-0011-0000-0000-0000000FF1CE}. If the bold numbers start with 0 its x86, 1 is x64
For me it was in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-0057-0000-0000-0000000FF1CE}
Source
此 InnoSetup 代码适用于 Win 10x64 和 Office 2016 x86(使用“HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration”和密钥“Platform”)
This InnoSetup code is working for me under Win 10x64 and Office 2016 x86 (using 'HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration' and key 'Platform')
不是通过注册表,而是通过命令行工具:
https://stackoverflow.com/a/6194710/2885897
C:\Users \me>assoc .msg
.msg=Outlook.File.msg.15
C:\Users\me>ftype Outlook.File.msg.15
Outlook.File.msg.15="C:\Program Files (x86 )\Microsoft Office\Root\Office16\OUTLOOK.EXE" /f "%1"
Not via the registry but via commandline tools:
https://stackoverflow.com/a/6194710/2885897
C:\Users\me>assoc .msg
.msg=Outlook.File.msg.15
C:\Users\me>ftype Outlook.File.msg.15
Outlook.File.msg.15="C:\Program Files (x86)\Microsoft Office\Root\Office16\OUTLOOK.EXE" /f "%1"
编辑:不触及注册表键的解决方案 - 抱歉,Op。
我发现 C# 有一个解决方案 - 原始解决方案可以在这里找到:
https:// /blogs.msdn.microsoft.com/webdav_101/2016/07/26/sample-detecting-installed-outlook-and-its-bitness/
我根据自己的需要对其进行了一些修改。
只需将正确的 OutlookPath 传递给 GetOutlookBitness()
EDIT : Solution without touching RegistryKeys - im Sorry Op.
I found out that there is a solution in C# - the original can be found here :
https://blogs.msdn.microsoft.com/webdav_101/2016/07/26/sample-detecting-installed-outlook-and-its-bitness/
I modified it a bit for my needs.
just pass the correct outlookPath to GetOutlookBitness()
我在这两个文件夹中都没有名为 bitness 的密钥。我在这两个文件夹中都有一个名为“default”的键,其值为“unset” 我的计算机附带了 Office 2010 starter(我假设是 64 位)。我删除了它并尝试完整安装 32 位 Office。我不断收到以下消息。文件不兼容,请检查您是否需要 x86 或 x64 版本的程序。
对我有什么建议吗?
I don't have a key called bitness in either of these folders. I do have a key called "default" in both of these folders and the value is "unset" My computer came with office 2010 starter (I assume 64 bit). I removed it and tried to do a full install of 32 bit office. I keep getting the following message. the file is incompatible, check to see whether you need x86 or x64 version of the program.
any advice for me?
@clatonh:这是我的电脑上注册表的路径:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-002A-0000-1000-0000000FF1CE}
而且它绝对是 64 位操作系统上的 32 位安装。
@clatonh: this is the path of the registry on my PC:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Registration{90140000-002A-0000-1000-0000000FF1CE}
and it's definitely a 32-bit-installation on a 64-bit OS.