批处理文件代码以检测32位与64位办公室不起作用 [英] batch file code to detect 32-bit vs 64-bit office not working

查看:54
本文介绍了批处理文件代码以检测32位与64位办公室不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个批处理文件放在一起,以便在用户运行时选择适当的可执行文件位版本.我在stackoverflow上找到了以下代码:批处理文件检查办公体系结构版本问题是,当我将其粘贴到桌面上的文本文件中并在安装了64位Office 2010的虚拟机中将其重命名为.bat时,它不起作用:它声称它是32位,这是在Windows中设置的默认值.编码.我不擅长检查注册表项,所以我想知道在某个实际可行的地方是否没有现成的版本.我也想知道为什么没有简单的方法来确定这一点.我以为这是Microsoft可以使开发人员轻松访问的东西.

I'm trying to put together a batch file that would select the appropriate bit version of executables when run by the user. I found this code on stackoverflow: Batch file check office architecture version The problem is that it does not work when I paste it into a text file on my desktop and rename it .bat in my virtual machine that has 64-bit Office 2010 installed: it claims it is 32-bit, the default value set in the code. Not being adept in checking registry entries, I'm wondering if there isn't a ready-made version out there somewhere that actually works. I'm also wondering why there isn't a simple way to determine this. I would have thought that this is something that Microsoft would make easily accessible to developers.

推荐答案

如果要检查Microsoft Office的位数,版本和安装位置,可以对该脚本进行测试,以查看它是否对您有用更好:

If you're wanting to check the bitness, version and install location of Microsoft Office, you could give this script a test to see if it works for you any better:

@Echo Off
If Defined PROCESSOR_ARCHITEW6432 (
    Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0"&Exit /B)
Set /A "OSA=MWB=%PROCESSOR_ARCHITECTURE:~-2%"
If %OSA%==86 Set "MWB=32"
Set "MOB="&Set "GUID="&Set "REG=%__AppDir__%reg.exe"
Call :Chk
If Not Defined MOB If %MWB%==64 Call :Chk \Wow6432Node
If Not Defined MOB (Echo Microsoft Office product not installed&GoTo :EndIt
)Else If Not Defined IOV (Echo Unable to determine Microsoft Office version
    GoTo :EndIt)
Echo %MWB%-bit OS with an Office 20%IOV% %MOB%-bit product installed in %OIL%
:EndIt
>Nul Timeout -1
GoTo :EOF

:Chk
Set "MOB="&Set "GUID="&Set "OIL="
Set "Key=HKLM\Software%1\Microsoft\Windows\CurrentVersion\Uninstall"
For /F Delims^= %%A In ('""%REG%" Query "%Key%" /K /F "*-001B-*0FF1CE}""'
)Do Set "GUID=%%~nxA"&GoTo :Next
:Next
If Not "%GUID:~-1%"=="}" Set "GUID="
If Not Defined GUID Exit /B
Set "MOB=32"&If "%GUID:~20,1%"=="1" Set "MOB=64"
If "%GUID:~4,1%"=="2" Set "IOV=07"
If "%GUID:~4,1%"=="4" Set "IOV=10"
If "%GUID:~4,1%"=="5" Set "IOV=13"
If "%GUID:~4,1%"=="6" Set "IOV=16"
If Not Defined IOV Exit /B
For /F Tokens^=2* %%A In ('""%REG%" Query "%Key%\%GUID%" /V "InstallLocation""'
)Do Set "OIL=%%B"
Exit /B

但是请注意,此脚本旨在与版本从 2007 2016 (含)的Windows Microsoft Office产品一起使用.该脚本仅检查Microsoft Word的特定卸载密钥,(假定只有在极少数情况下,有人安装Office而不包含Word产品),并且不能保证所有版本都可以.使用相同的卸载密钥.

Please note however, that this script was designed to work with Windows Microsoft Office products from versions 2007 up to 2016 inclusive. The script only checks for a specific uninstall key for Microsoft Word, (it is assumed that only in very rare cases would somebody install Office without including the Word product), and there is no guarantee that all versions will use the same uninstall key.

我不会针对您的问题的任何添加/更改来修改此代码,也不会出于目的之外的其他目的提供修改帮助.

这篇关于批处理文件代码以检测32位与64位办公室不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆