检测MS-Office的已安装版本可以通过以下几种方式:
$officeVersions = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object { $_.DisplayName -like 'Microsoft Office*' } | Select-Object -Property DisplayName, DisplayVersion
if ($officeVersions) {
Write-Host "已安装的MS-Office版本:"
foreach ($version in $officeVersions) {
Write-Host $version.DisplayName, $version.DisplayVersion
}
} else {
Write-Host "未安装MS-Office"
}
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE 'Microsoft Office%'")
If colItems.Count > 0 Then
WScript.Echo "已安装的MS-Office版本:"
For Each objItem in colItems
WScript.Echo objItem.Name & " " & objItem.Version
Next
Else
WScript.Echo "未安装MS-Office"
End If
以上是几种常用的检测MS-Office已安装版本的方法。根据实际需求选择合适的方式进行检测。
领取专属 10元无门槛券
手把手带您无忧上云