问题描述
我正在编写一个 powershell 脚本,它将为我的 web 应用程序安装一些依赖项.在我的脚本中,我经常遇到检查是否安装了特定应用程序的问题.似乎有一种独特的方法可以检查每个应用程序是否存在一个应用程序(即:通过检查此文件夹的存在或 c: 上的此文件).有没有办法通过查询已安装的应用程序列表来检查应用程序是否已安装?
I'm writing a powershell script that will install some dependencies for my webapp. In my script, I'm running into a recurring problem of checking if a particular application is installed. it seems there's a unique way of checking if an application exists for each application (ie: by checking the existing of this folder or this file on c:). Is there not a way that i can check if an application is installed by querying a list of installed applications?
推荐答案
这是我有时使用的代码(不是太频繁,所以...).详情请参阅帮助评论.
Here is the code I use sometimes (not too often, so...). See the help comments for details.
<#
.SYNOPSIS
Gets uninstall records from the registry.
.DESCRIPTION
This function returns information similar to the "Add or remove programs"
Windows tool. The function normally works much faster and gets some more
information.
Another way to get installed products is: Get-WmiObject Win32_Product. But
this command is usually slow and it returns only products installed by
Windows Installer.
x64 notes. 32 bit process: this function does not get installed 64 bit
products. 64 bit process: this function gets both 32 and 64 bit products.
#>
function Get-Uninstall
{
# paths: x86 and x64 registry keys are different
if ([IntPtr]::Size -eq 4) {
$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
}
else {
$path = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
}
# get all data
Get-ItemProperty $path |
# use only with name and unistall information
.{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} |
# select more or less common subset of properties
Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, HelpLink, UninstallString |
# and finally sort by name
Sort-Object DisplayName
}
Get-Uninstall
这篇关于如何检查是否安装了特定的 MSI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!