Wir haben Powershell-Funktion geschrieben, um zu finden, ob 64 Bit oder 32 Bit MSI installiert ist. Wir überprüfen den Outlook-Registrierungsschlüssel, da dieser die Informationen über die Bitness enthält.Wie finden Sie, ob 64-Bit oder 32-Bit-Excel über Powershell installiert ist?
Aber wenn Benutzer nur Excel ohne Outlook installieren, ist dieser Registrierungsschlüssel nicht zuverlässig (In 64-Bit-Betriebssystem ist es verfügbar, aber in 32-Bit-Betriebssystem ist es nicht verfügbar).
Folgendes ist die Funktion, die wir geschrieben haben, um das zu finden. Da der Registrierungsschlüssel nicht verfügbar ist, funktioniert er nicht. Gibt es eine andere Möglichkeit, die Bissigkeit von Excel zu finden?
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
}
Sie -ErrorAction SilentlyContinue am Ende Ihrer reg querys Fehler zu verhindern, zeigt und halten zu gehen, wenn die Schlüssel nicht existieren können. Beispiel - $ Reg32Key = Get-ItemProperty -path "HKLM: \ SOFTWARE \ Microsoft \ Windows \ AktuelleVersion \ Uninstall \ Google Chrome" -name "Version" -ErrorAction SilentlyContinue –