Separated Prerequisites function
parent
17b02dfc95
commit
0c0f95e97c
|
@ -119,74 +119,13 @@ param(
|
|||
<# FUNCTIONS #>
|
||||
|
||||
#Include external Functions
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Install-Prerequisites.ps1"
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Invoke-DirProtect.ps1"
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Update-WinGet.ps1"
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Update-StoreApps.ps1"
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Add-Shortcut.ps1"
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Write-ToLog.ps1"
|
||||
|
||||
function Install-Prerequisites {
|
||||
|
||||
Write-ToLog "Checking prerequisites..." "Yellow"
|
||||
|
||||
#Check if Visual C++ 2019 or 2022 installed
|
||||
$Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*"
|
||||
$Visual2022 = "Microsoft Visual C++ 2015-2022 Redistributable*"
|
||||
$path = Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.GetValue("DisplayName") -like $Visual2019 -or $_.GetValue("DisplayName") -like $Visual2022 }
|
||||
|
||||
#If not installed, ask for installation
|
||||
if (!($path)) {
|
||||
#If -silent option, force installation
|
||||
if ($Silent) {
|
||||
$InstallApp = $True
|
||||
}
|
||||
else {
|
||||
#Ask for installation
|
||||
$MsgBoxTitle = "Winget Prerequisites"
|
||||
$MsgBoxContent = "Microsoft Visual C++ 2015-2022 is required. Would you like to install it?"
|
||||
$MsgBoxTimeOut = 60
|
||||
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32)
|
||||
if ($MsgBoxReturn -ne 7) {
|
||||
$InstallApp = $True
|
||||
}
|
||||
}
|
||||
#Install if approved
|
||||
if ($InstallApp) {
|
||||
try {
|
||||
#Get proc architecture
|
||||
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
|
||||
$OSArch = "arm64"
|
||||
}
|
||||
elseif ($env:PROCESSOR_ARCHITECTURE -like "*64*") {
|
||||
$OSArch = "x64"
|
||||
}
|
||||
else {
|
||||
$OSArch = "x86"
|
||||
}
|
||||
|
||||
$SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
|
||||
$Installer = $WAUinstallPath + "\VC_redist.$OSArch.exe"
|
||||
Write-ToLog "-> Downloading VC_redist.$OSArch.exe..."
|
||||
Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force)
|
||||
Write-ToLog "-> Installing VC_redist.$OSArch.exe..."
|
||||
Start-Process -FilePath $Installer -Args "/passive /norestart" -Wait
|
||||
Start-Sleep 1
|
||||
Remove-Item $Installer -ErrorAction Ignore
|
||||
Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully`n" "Cyan"
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> MS Visual C++ 2015-2022 installation failed.`n" "Red"
|
||||
Start-Sleep 3
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-ToLog "-> MS Visual C++ 2015-2022 will not be installed.`n" "Magenta"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-ToLog "-> Prerequisites checked. OK`n" "Green"
|
||||
}
|
||||
}
|
||||
|
||||
function Install-WingetAutoUpdate {
|
||||
|
||||
|
@ -310,7 +249,6 @@ function Install-WingetAutoUpdate {
|
|||
$task.SetSecurityDescriptor($sec, 0)
|
||||
|
||||
# Configure Reg Key
|
||||
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
||||
New-Item $regPath -Force | Out-Null
|
||||
New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force | Out-Null
|
||||
New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null
|
||||
|
@ -544,6 +482,9 @@ Write-Host "`t Winget-AutoUpdate $WAUVersion`n" -ForegroundColor
|
|||
Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -ForegroundColor Magenta
|
||||
Write-Host "`t________________________________________________________`n"
|
||||
|
||||
#Define WAU registry key
|
||||
$Script:regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
||||
|
||||
if (!$Uninstall) {
|
||||
Write-ToLog " INSTALLING WAU" -LogColor "Cyan" -IsHeader
|
||||
Install-Prerequisites
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
function Install-Prerequisites {
|
||||
|
||||
try {
|
||||
|
||||
Write-ToLog "Checking prerequisites..." "Yellow"
|
||||
|
||||
#Check if Visual C++ 2019 or 2022 installed
|
||||
$Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*"
|
||||
$Visual2022 = "Microsoft Visual C++ 2015-2022 Redistributable*"
|
||||
$path = Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.GetValue("DisplayName") -like $Visual2019 -or $_.GetValue("DisplayName") -like $Visual2022 }
|
||||
if (!($path)) {
|
||||
try {
|
||||
Write-ToLog "MS Visual C++ 2015-2022 is not installed" "Red"
|
||||
|
||||
#Get proc architecture
|
||||
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
|
||||
$OSArch = "arm64"
|
||||
}
|
||||
elseif ($env:PROCESSOR_ARCHITECTURE -like "*64*") {
|
||||
$OSArch = "x64"
|
||||
}
|
||||
else {
|
||||
$OSArch = "x86"
|
||||
}
|
||||
|
||||
#Download and install
|
||||
$SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
|
||||
$Installer = "$env:TEMP\VC_redist.$OSArch.exe"
|
||||
Write-ToLog "-> Downloading $SourceURL..."
|
||||
Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile $Installer
|
||||
Write-ToLog "-> Installing VC_redist.$OSArch.exe..."
|
||||
Start-Process -FilePath $Installer -Args "/passive /norestart" -Wait
|
||||
Start-Sleep 3
|
||||
Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully." "Green"
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> MS Visual C++ 2015-2022 installation failed." "Red"
|
||||
Start-Sleep 3
|
||||
}
|
||||
finally {
|
||||
Remove-Item $Installer -ErrorAction Ignore
|
||||
}
|
||||
}
|
||||
|
||||
#Check if Microsoft.VCLibs.140.00.UWPDesktop is installed
|
||||
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers)) {
|
||||
try {
|
||||
Write-ToLog "Microsoft.VCLibs.140.00.UWPDesktop is not installed" "Red"
|
||||
#Download
|
||||
$VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
||||
$VCLibsFile = "$env:TEMP\Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
||||
Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..."
|
||||
Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile
|
||||
#Install
|
||||
Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
|
||||
Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null
|
||||
Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully." "Green"
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red"
|
||||
}
|
||||
finally {
|
||||
Remove-Item -Path $VCLibsFile -Force
|
||||
}
|
||||
}
|
||||
|
||||
Write-ToLog "Prerequisites checked. OK`n" "Green"
|
||||
|
||||
}
|
||||
catch {
|
||||
|
||||
Write-ToLog "Prerequisites checked failed`n" "Red"
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -31,25 +31,6 @@ Function Update-WinGet {
|
|||
#Check if the current available WinGet is newer than the installed
|
||||
if ($WinGetAvailableVersion -gt $WinGetInstalledVersion) {
|
||||
|
||||
#Check if Microsoft.VCLibs.140.00.UWPDesktop is installed
|
||||
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers)) {
|
||||
try {
|
||||
#Download
|
||||
$VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
||||
$VCLibsFile = "$env:TEMP\Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
||||
Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..."
|
||||
Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile
|
||||
#Install
|
||||
Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
|
||||
Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null
|
||||
Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully." "Green"
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red"
|
||||
}
|
||||
Remove-Item -Path $VCLibsFile -Force
|
||||
}
|
||||
|
||||
#Install WinGet MSIXBundle in SYSTEM context
|
||||
try {
|
||||
#Download WinGet MSIXBundle
|
||||
|
|
Loading…
Reference in New Issue