(こ、こいつ動くぞ→)
クイック実行(Click To Run、C2R)かWindowsインストーラー(MSI)か、32 ビット Office か 64 ビット Office かを識別しようとがんばったもの)。
ちゃんと動かないかもしれないので、あくまでも参考として。無保証。
すべての環境が手元にあるわけでは無いので、ロジックには想像して書いたものも含みます。以下の環境はチェックできると思う(うちにある環境)。
・C2R版Office 2016(32ビット Office on 64ビット Windows or 32 ビット Windows)
・MSI版Office 2013(32ビット on 64ビット Windows)
・C2R版Office 2013(32ビット on 64ビット Windows)
64 ビット OS 上の 64 ビット Office か32ビット Office かは mso.dll のパスと、Program Files (x86) の下のアプリのバイナリ(.EXE)の両方で識別しようとしているけど、Office 2013 については一部、無駄な判断をしているかもしれない。Word、Excel、PowerPoint、Outlook だけを既定のパス(だと思うパス)を調べているけど、$ofapps にアプリの実行ファイル名を追加すれば、Office スイートの他のアプリにも対応できるかも(MSACCESS.EXE とか ONENOTE.EXE とか、ただし Visio は除く)。
[officemsiorc2r.ps1]
# This sample script is not tested.
#
$ofapps = "WINWORD.EXE","EXCEL.EXE","POWERPNT.EXE","OUTLOOK.EXE"
Write-Host "Search Office 2016 and Office 2013 installation..."
$ofapps |foreach { Write-Host "Search"$_" in default path..."}
Write-Host ""
$32bitos = $true
if (Test-Path -Path env:\ProgramFiles`(x86`)) {
$32bitos = $false
}
Write-Host "Microsoft Office 2016 (C2R):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\root\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\root\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2016 (MSI):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2013 (C2R):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office 15\root\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
$targetofpath = $env:ProgramFiles + "\Microsoft Office 15\root\vfs\ProgramFilesCommonX86\Microsoft Shared\OFFICE15\mso.dll"
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office 15\root\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2013 (MSI):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
$targetofpath = $env:ProgramFiles + "\Common Files\microsoft shared\OFFICE15\Mso.dll"
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(64-bit) is installed."
} else {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
#
$ofapps = "WINWORD.EXE","EXCEL.EXE","POWERPNT.EXE","OUTLOOK.EXE"
Write-Host "Search Office 2016 and Office 2013 installation..."
$ofapps |foreach { Write-Host "Search"$_" in default path..."}
Write-Host ""
$32bitos = $true
if (Test-Path -Path env:\ProgramFiles`(x86`)) {
$32bitos = $false
}
Write-Host "Microsoft Office 2016 (C2R):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\root\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\root\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2016 (MSI):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\Office16\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2013 (C2R):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office 15\root\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
$targetofpath = $env:ProgramFiles + "\Microsoft Office 15\root\vfs\ProgramFilesCommonX86\Microsoft Shared\OFFICE15\mso.dll"
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
Write-Host " "$ofapp "(64-bit) is installed."
}
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office 15\root\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
Write-Host "Microsoft Office 2013 (MSI):"
foreach ($ofapp in $ofapps) {
$targetofpath = $env:ProgramFiles + "\Microsoft Office\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
if($32bitos) {
Write-Host " "$ofapp "(32-bit) is installed."
} else {
$targetofpath = $env:ProgramFiles + "\Common Files\microsoft shared\OFFICE15\Mso.dll"
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(64-bit) is installed."
} else {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
if (!($32bitos)){
$targetofpath = ${env:ProgramFiles(x86)} + "\Microsoft Office\Office15\" + $ofapp
if (Test-Path -Path $targetofpath) {
Write-Host " "$ofapp "(32-bit) is installed."
}
}
}
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。