我正在写一个powershell脚本,将为我的webapp安装一些依赖关系。在我的脚本中,我遇到了一个反复检查特定应用程序是否安装的问题。似乎有一种独特的方式来检查每个应用程序是否存在应用程序(即:通过检查此文件夹或此文件的现有存在:)。是否没有办法通过查询已安装的应用程序列表来检查应用程序是否已安装?我如何检查是否安装了特定的MSI?
6
A
回答
10
这里是我有时使用的代码(不要过于频繁,所以...)。详细信息请参阅帮助注释。
<#
.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
4
让你的脚本扫描:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
set-location HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
Get-ChildItem | foreach-object { $_.GetValue("DisplayName") }
12
要获取安装的应用程序的列表尝试:
$r = Get-WmiObject Win32_Product | Where {$_.Name -match 'Microsoft Web Deploy' }
if ($r -ne $null) { ... }
参见Win32_Product的文档获取更多信息。
相关问题
- 1. 检查设备上是否安装了特定证书
- 2. 如何检查是否闪光的特定版本安装
- 3. 如何检查是否使用Ant安装了特定的Django应用程序?
- 4. 如何检查我是否已正确安装了pymunk
- 5. 检查Java是否安装了Bash
- 6. GWT检查是否安装了闪存
- 7. gwt检查是否安装了jre
- 8. 检查是否安装了dll
- 9. 检查是否安装了Yahoo Messenger
- 10. 检查是否安装了J#框架
- 11. 检查是否安装了软件包
- 12. 检查是否安装了咕噜声?
- 13. 如何检测是否安装了numpy
- 14. 如何检查特定库是否安装在我的系统中?
- 15. 如何检查Qpid是否安装?
- 16. 如何检查Flash是否安装?
- 17. 如何检查LAMP是否安装?
- 18. 如何检查Suhosin是否安装?
- 19. 如何检查插件是否安装?
- 20. 如何检查是否定义了特定的jquery-easing方法?
- 21. 如何检测Android手机是否安装了特定的应用程序?
- 22. 如何检查我的系统中是否安装了特定的修补程序(Windows更新)?
- 23. 如何检查之前是否安装了iPhone应用程序?
- 24. 如何检查是否安装了.Net框架[C#/ WPF]
- 25. 如何检查用户是否安装了应用程序?
- 26. 如何检查是否安装了Apple Maps
- 27. 如何检查emacs是否安装了库?
- 28. 如何检查是否安装了paho mqtt
- 29. 如何检查Mozilla中是否安装了Firebug?
- 30. 如何检查是否安装了SQL Server 2005或2008
请注意,如果在安装程序数据库中发现错误,Get-WmiObject Win32_Product可能会修改目标系统。这很简单,并且是一个非常有用的功能。但是,如果您不仅仅是使用它来检测已安装的应用程序,还可以做好更多的工作。 – 2014-09-03 13:38:49