我们已经编写了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
}
没有仿真器,您将无法在32位版本的Windows上运行64位软件(是否可以在32位计算机上执行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.
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句