是否有任何内置命令可以检查程序是否已经安装,而不是由Chocolatey安装?
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
}
function Is-App-Installed($appName) {
$appToMatch = "*" + $appName + "*"
$result = Get-InstalledApps | where {$_.DisplayName -like $appToMatch}
return $result
}