Some ways to detect whether required VCRedist is installed:
# Assets
$64BitOS = [System.Environment]::Is64BitOperatingSystem
$64BitProcess = [System.Environment]::Is64BitProcess
# Require running system native process
if ($64BitOS -and -not $64BitProcess) {
Throw 'Please run PowerShell in the systen native architecture (x64 PowerShell if x64 Windows).'
}
# Check that uninstall information exists in the registry
Test-Path -Path (
[string]::Format(
'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\{0}\Microsoft\VisualStudio\14.0\VC\Runtimes\X{1}',
$(if($64BitOS -and $64BitProcess){'WOW6432Node\'}),
$(if($64BitOS){'64'}else{'86'})
)
)
# Check that one required DLL exists on the file system
[System.IO.File]::Exists(
[string]::Format(
'{0}\system32\concrt140.dll',
$env:windir
)
)
I've done something similar with my WinGet + Intune R'n'D project:
Describe the feature or improvement you're requesting
For Windows Server 2019: Don't download and install VCRedist if already installed.
https://github.com/asheroto/winget-install/blob/958f61fde5291c35943e0236895e49aafa99637d/winget-install.ps1#L872-L890
Additional context
Some ways to detect whether required VCRedist is installed:
I've done something similar with my WinGet + Intune R'n'D project: