From d27e73802cb7412d2794ff71b605f501e2808fa2 Mon Sep 17 00:00:00 2001 From: Romanitho <96626929+Romanitho@users.noreply.github.com> Date: Thu, 27 Jan 2022 00:09:24 +0100 Subject: [PATCH] Visual C++ check --- winget-install-and-update.ps1 | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/winget-install-and-update.ps1 b/winget-install-and-update.ps1 index e92c961..2fc2bd4 100644 --- a/winget-install-and-update.ps1 +++ b/winget-install-and-update.ps1 @@ -2,6 +2,20 @@ $WingetUpdatePath = "$env:ProgramData\winget-update" Write-host "Instaling to $WingetUpdatePath\" +#Check if Visual C++ 2015-2019 is installed. If not, download and install +$app = "Microsoft Visual C++ 2019 X64*" +$path = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -like $app } | Select-Object -Property Displayname, DisplayVersion +if (!($path)){ + Write-host "MS Visual C++ 2015-2019 is not installed." + Write-host "Downloading VC_redist.x64.exe..." + $SourceURL = "https://aka.ms/vs/16/release/VC_redist.x64.exe" + $Installer = $env:TEMP + "\vscode.exe" + Invoke-WebRequest $SourceURL -OutFile $Installer + Write-host "Installing VC_redist.x64.exe..." + Start-Process -FilePath $Installer -Args "-q" -Wait + Remove-Item $Installer +} + try{ #Copy files to location if (!(Test-Path $WingetUpdatePath)){ @@ -14,20 +28,6 @@ try{ & reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v DisplayName /t REG_EXPAND_SZ /d "Application Update" /f | Out-Null & reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v IconUri /t REG_EXPAND_SZ /d %SystemRoot%\system32\@WindowsUpdateToastIcon.png /f | Out-Null - #Check if Visual C++ 2015-2019 is installed. If not, download and install - $app = "Microsoft Visual C++ 2019 X64*" - $path = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -like $app } | Select-Object -Property Displayname, DisplayVersion - if (!($path)){ - Write-host "MS Visual C++ 2015-2019 is not installed." - Write-host "Downloading VC_redist.x64.exe..." - $SourceURL = "https://aka.ms/vs/16/release/VC_redist.x64.exe" - $Installer = $env:TEMP + "\vscode.exe" - Invoke-WebRequest $SourceURL -OutFile $Installer - Write-host "Installing VC_redist.x64.exe..." - Start-Process -FilePath $Installer -Args "-q" -Wait - Remove-Item $Installer - } - # Settings for the scheduled task for Updates $taskAction = New-ScheduledTaskAction –Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`"" $taskTrigger1 = New-ScheduledTaskTrigger -AtLogOn @@ -56,4 +56,4 @@ try{ catch{ Write-host "`nInstallation failed! Run me with admin rights" -ForegroundColor Red Start-sleep 5 -} \ No newline at end of file +}