Message box if not run as silent

pull/46/head
Romain 2022-04-09 10:42:00 +02:00
parent 66175a23b0
commit 3d61d57693
1 changed files with 28 additions and 10 deletions

View File

@ -55,15 +55,23 @@ function Install-Prerequisites{
if (!($path)){ if (!($path)){
#If -silent option, force installation #If -silent option, force installation
if ($Silent){ if ($Silent){
$InstallApp = "y" $InstallApp = 1
} }
else{ else{
#Ask for installation #Ask for installation
while("y","n" -notcontains $InstallApp){ $MsgBoxTitle = "Winget Prerequisites"
$InstallApp = Read-Host "[Prerequisite for Winget] Microsoft Visual C++ 2019 is not installed. Would you like to install it? [Y/N]" $MsgBoxContent = "Microsoft Visual C++ 2015-2019 is required. Would you like to install it?"
$MsgBoxTimeOut = 20
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent,$MsgBoxTimeOut,$MsgBoxTitle,4+32)
if ($MsgBoxReturn -ne 7) {
$InstallApp = 1
}
else {
$InstallApp = 0
} }
} }
if ($InstallApp -eq "y"){ #Install if approved
if ($InstallApp -eq 1){
try{ try{
if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){ if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){
$OSArch = "x64" $OSArch = "x64"
@ -86,6 +94,9 @@ function Install-Prerequisites{
Start-Sleep 3 Start-Sleep 3
} }
} }
else{
Write-host "MS Visual C++ 2015-2019 wil not be installed." -ForegroundColor Magenta
}
} }
else{ else{
Write-Host "Prerequisites checked. OK" -ForegroundColor Green Write-Host "Prerequisites checked. OK" -ForegroundColor Green
@ -162,7 +173,6 @@ function Install-WingetAutoUpdate{
} }
function Uninstall-WingetAutoUpdate{ function Uninstall-WingetAutoUpdate{
Write-Host "Starting uninstall"
try{ try{
#Check if installed location exists and delete #Check if installed location exists and delete
if (Test-Path ($WingetUpdatePath)){ if (Test-Path ($WingetUpdatePath)){
@ -189,15 +199,22 @@ function Start-WingetAutoUpdate{
if (!($DoNotUpdate)){ if (!($DoNotUpdate)){
#If -Silent, run Winget-AutoUpdate now #If -Silent, run Winget-AutoUpdate now
if ($Silent){ if ($Silent){
$RunWinget = "y" $RunWinget = 1
} }
#Ask for WingetAutoUpdate #Ask for WingetAutoUpdate
else{ else{
while("y","n" -notcontains $RunWinget){ $MsgBoxTitle = "Winget-AutoUpdate"
$RunWinget = Read-Host "Start Winget-AutoUpdate now? [Y/N]" $MsgBoxContent = "Would you like to run Winget-AutoUpdate now?"
$MsgBoxTimeOut = 20
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent,$MsgBoxTimeOut,$MsgBoxTitle,4+32)
if ($MsgBoxReturn -ne 7) {
$RunWinget = 1
}
else {
$RunWinget = 0
} }
} }
if ($RunWinget -eq "y"){ if ($RunWinget -eq 1){
try{ try{
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
@ -227,11 +244,12 @@ Write-Host "`t###################################"
Write-Host "`n" Write-Host "`n"
if (!$Uninstall){ if (!$Uninstall){
Write-host "Installing to $WingetUpdatePath\" Write-host "Installing WAU to $WingetUpdatePath\"
Install-Prerequisites Install-Prerequisites
Install-WingetAutoUpdate Install-WingetAutoUpdate
} }
else { else {
Write-Host "Uninstall WAU"
Uninstall-WingetAutoUpdate Uninstall-WingetAutoUpdate
} }