1
我們編寫了powershell函數來查找是否安裝了64位或32位msi。我們正在檢查Outlook註冊表項,因爲它是具有位信息的那個。如何查找是否通過Powershell安裝了64位或32位excel?
但是,當用戶只安裝沒有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
}
您可以使用-ErrorAction SilentlyContinue你REG querys月底停止顯示,錯誤並保持如果不存在鍵去。示例 - $ Reg32Key = Get-ItemProperty -path「HKLM:\ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ Google Chrome」-name「Version」-ErrorAction SilentlyContinue –