Powershell静默安装问题

Powershell silent installation issue

如果我们尝试使用已安装在服务器中的 powershell 安装软件,会发生什么情况。例如,我的服务器中已经有 notepad++,现在我尝试使用 powershell 在我的服务器中安装相同的 notepad++ 版本。那么输出会是什么?另外,请问有什么办法可以知道服务器上是否已经安装了一个软件

安装程序有很多种,但大多数都在添加/删除程序列表中添加记录,但没有保证。 Here is C++ code to scan the registry and check via WMI。当然,您可以使用脚本来代替,但这并不是一门精确的科学来查找已安装的内容 - 一些安装程序非常自定义并且 non-standard 并遵循一些准则。

注册表项:

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

MSI 软件包:

对于 MSI 软件包,有一些方法可以检查是否安装了完全相同的版本或相关的版本。如果你有微星的产品代码,你可以简单地检查是否安装了这样的:

Dim installer : Set installer = CreateObject("WindowsInstaller.Installer")
MsgBox installer.ProductState("{00000000-0000-0000-0000-000000000001}") ' <= PRODUCT CODE

Longer sample linked here.

您可以使用多种方法找到已安装 MSI 的产品代码:

如果您有 MSI 系列的升级代码,您可以使用 RelatedProducts 方法查明是否安装了相关产品:

Set installer = CreateObject("WindowsInstaller.Installer")
Set upgrades = installer.RelatedProducts("{UPGRADE-CODE-GUID-HERE}")

For Each u In upgrades
   MsgBox u, vbOKOnly, "Product Code: "
Next

。您可以通过使用 Orca 查看 属性 table 来获取要安装的 MSI 的升级代码。

实用方法:

一个选项是从每个安装中识别一个密钥文件,并使用您想要的任何语言检查它是否存在 - 脚本就可以。

Set fso = CreateObject("Scripting.FileSystemObject")
MsgBox fso.GetFileVersion("C:\Windows\System32\vcruntime140.dll")

The above script snippet from this rant on how to find the installed VCRedist version.


Link: