如何检查程序是否已安装并安装(如果不安装)?

编程入门 行业动态 更新时间:2024-10-26 20:34:04
本文介绍了如何检查程序是否已安装并安装(如果不安装)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于完整性检查,我宁愿不使用WMI。

I would rather not use WMI due the integrity check.

这就是我所做的不起作用:

This is what I have that does not work:

$tempdir = Get-Location $tempdir = $tempdir.tostring() $reg32 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" $reg64 = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" if((Get-ItemProperty $reg32 | Select-Object DisplayName | Where-Object { $_.DisplayName -Like '*Microsoft Interop Forms*' } -eq $null) -Or (Get-ItemProperty $reg64 | Select-Object DisplayName | Where-Object { $_.DisplayName -Like '*Microsoft Interop Forms*' } -eq $null)) { (Start-Process -FilePath $tempdir"\microsoft.interopformsredist.msi" -ArgumentList "-qb" -Wait -Passthru).ExitCode }

它总是返回false。如果我将它切换到 -ne $ null 它总是返回true,所以我知道它正在检测 $ null 输出,我相信(但可能是错的), Get-ItemProperty 返回的结果应该是 $ null 。

It always returns false. If I switch it to -ne $null it always returns true so I know it is detecting $null output even though, I believe (but could be wrong), the Get-ItemProperty is returning a result that should be counting as something other than $null.

推荐答案

$tempdir = Get-Location $tempdir = $tempdir.tostring() $appToMatch = '*Microsoft Interop Forms*' $msiFile = $tempdir+"\microsoft.interopformsredist.msi" $msiArgs = "-qb" function Get-InstalledApps { if ([IntPtr]::Size -eq 4) { $regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' } else { $regpath = @( 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' ) } Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName } $result = Get-InstalledApps | where {$_.DisplayName -like $appToMatch} If ($result -eq $null) { (Start-Process -FilePath $msiFile -ArgumentList $msiArgs -Wait -Passthru).ExitCode }

更多推荐

如何检查程序是否已安装并安装(如果不安装)?

本文发布于:2023-07-17 06:37:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并安装   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!