我们编写了 powershell 函数来查找是否安装了 64 位或 32 位 msi。我们正在检查 Outlook 注册表项,因为它具有位数信息。
但是当用户仅安装 Excel 而不安装 Outlook 时,此注册表项不可靠(在 64 位操作系统中可用,但在 32 位操作系统中不可用)。
以下是我们编写的用于查找该值的函数。现在,由于注册表项不可用,因此它无法工作。还有其他方法可以找到 excel 的位数吗?
Function Get-OfficeVersionInstalled
{
$NoExcelInstalled = '0'
$excelApplicationRegKey = "HKLM:\SOFTWARE\Classes\Excel.Application\CurVer"
if( Test-Path $excelApplicationRegKey)
{
$excelApplicationCurrentVersion = (Get-ItemProperty $excelApplicationRegKey).'(default)'
#Get version number alone from registry value
$($excelApplicationCurrentVersion -replace "Excel.Application.","")
}
else
{
$NoExcelInstalled
}
}
Function Test-Excel2013AndAbove
{
Param
(
[ValidateSet("x64", "x86")]
$Edition="x64"
)
$isExpectedEditionInstalled = $false
$officeVersion = Get-OfficeVersionInstalled
$office2013Version = 15
if( $officeVersion -ge $office2013Version) {
# In registry, version will be with decimal
$officeVersion = $officeVersion+".0"
# Outlook key is having bitness which will decide the edition.
# Even if outlook is not installed this key will be present.
# This is the only place where we can reliably find the edition of Excel
$OutlookKey = "HKLM:\SOFTWARE\Microsoft\Office\$officeVersion\Outlook"
$OutlookWow6432NodeKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\$officeVersion\Outlook"
if(Test-Path $OutlookKey)
{
$officeRegKey = $OutlookKey
}
else
{
$officeRegKey = $OutlookWow6432NodeKey
}
$BitNess = (Get-ItemProperty $officeRegKey).BitNess
if($BitNess -eq $Edition)
{
$isExpectedEditionInstalled = $true
}
else
{
$isExpectedEditionInstalled = $false
}
}
return $isExpectedEditionInstalled
}
最佳答案
如果没有模拟器,您无法在 32 位版本的 Windows 上运行 64 位软件 ( Is there any way to execute 64-bit programs on a 32-bit computer? )。这意味着,如果您检测到 32 位操作系统,则任何本地非模拟安装的 Excel(如果有)都将是 32 位。
这里有一些伪代码来执行此操作:
if (OS.BitSize == 32)
{
Check if Excel installed. If so, then it is 32 bit.
}
else
{
//64 bit OS
Check registry key to determine whether 32 or 64 bit Excel is installed.
}
关于excel - 如何通过Powershell查看Excel安装的是64位还是32位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39125316/