gpt4 book ai didi

excel - 如何通过Powershell查找安装的是64位还是32位的excel?

转载 作者:可可西里 更新时间:2023-11-01 11:48:00 26 4
gpt4 key购买 nike

我们已经编写了 powershell 函数来查找是否安装了 64 位或 32 位 msi。我们正在检查 Outlook 注册表项,因为它具有位数信息。

但是当用户只安装没有 outlook 的 excel 时,这个注册表项是不可靠的(在 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
}

最佳答案

如果没有模拟器 (Is there any way to execute 64-bit programs on a 32-bit computer?),您无法在 32 位版本的 Windows 上运行 64 位软件。这意味着如果您检测到 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查找安装的是64位还是32位的excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39125316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com