2016-08-24 8 views
1

64ビットまたは32ビットのmsiがインストールされているかどうかを調べるpowershell関数を記述しました。私たちはビットレート情報を持っているので、Outlookのレジストリキーをチェックしています。64ビットまたは32ビットのExcelがPowershell経由でインストールされているかどうかを調べるには?

ただし、OutlookなしでExcelのみをインストールする場合、このレジストリキーは信頼できません(64ビットOSでは使用可能ですが、32ビットOSでは使用できません)。

私たちがそれを見つけるために書いた関数は次のとおりです。レジストリキーが利用できないので、それは機能しません。私たちが優秀さのビットを見つけることができる他の方法はありますか?

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 
} 
+0

キーが存在しない場合は、表示からエラーを停止し続けるために、あなたのREGのquerysの終わりに-ErrorAction SilentlyContinueというを使用することができますが。例 - $ Reg32Key = Get-ItemProperty -path "HKLM:¥SOFTWARE¥Microsoft¥Windows¥CurrentVersion¥Uninstall¥Google Chrome" -name "Version" -ErrorAction SilentlyContinue –

答えて

2

エミュレータ(Is there any way to execute 64-bit programs on a 32-bit computer?)なしで32ビットバージョンのWindowsで64ビットソフトウェアを実行することはできません。これは、32ビットOSを検出した場合、ローカルでエミュレートされていない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. 
} 
関連する問題