繁体   English   中英

使用 powershell 获取已安装的软件产品上下文

[英]Get installed software product context using powershell

我可以轻松地在一台机器上使用所有已安装的软件产品

Get-WmiObject -Class Win32_Product

现在我还想获取Product Context 如何使用 PowerShell 访问每个已安装产品的此信息。

在 VB 中,我通过使用 WindowsInstaller COM-Object 然后查询信息来做到这一点。 本质上是这样的:

Set Com = CreateObject('WindowsInstaller.Installer')
Set Products = Com.ProductsEx(vbNullString,"S-1-1-0",7)
For Each P in Products
  context = P.Context

我无法在 PowerShell 中复制

在 powershell 中使用 com object 很痛苦。 我会改用 vbscript 并将文本 output 保存到 powershell 模块,或找到一个 msi Z24483D399F0BEA308 com object 没有“类型库”或不支持“IDispatch”。 Windows Powershell in Action 附录第 2 版进入了它,但即使在那里它也不漂亮。 那个 vbscript 代码有错误。

我意识到这个问题有点陈旧,但我不同意似乎流行的观点,即在 PowerShell 中使用 Windows 安装程序在某种程度上是一种“痛苦”,并且比在 Z530BE07068945B461319ZE235 中使用它更复杂(这篇文章只是461319ZE235中的一个) ) .

I have found that VBScript Windows Installer code translates quite literally to PowerShell, which means there are numerous examples of VBScript Windows Installer scripts that can be adapted to PowerShell and used to learn how to work with Windows Installer in PowerShell.

对于安装上下文的这个特定问题,PowerShell 代码与 OP 给出的 VB 代码非常相似。

# code must be run with admin rights to use "S-1-1-0" SID
enum InstallContext {
    FirstVisible   =  0   # product visible to the current user
    None           =  0   # Invalid context for a product
    UserManaged    =  1   # user managed install context
    UserUnmanaged  =  2   # user non-managed context
    Machine        =  4   # per-machine context
    All            =  7   # All contexts. OR of all valid values
    AllUserManaged =  8   # all user-managed contexts
}

$Installer = New-Object -ComObject WindowsInstaller.Installer
foreach ($P in $Installer.ProductsEx("", "S-1-1-0", 7)) {
    [InstallContext]$P.Context()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM