mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 18:27:42 -06:00
Run winget in open powershell window if possible and handle update
This commit is contained in:
parent
d5fa8b54b9
commit
d7c23782ca
@ -35,22 +35,30 @@ Function Install-WinUtilProgramWinget {
|
|||||||
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
||||||
Write-Host "Starting install of $($Program.winget) with winget."
|
Write-Host "Starting install of $($Program.winget) with winget."
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode
|
||||||
if($status -eq 0){
|
if($status -eq 0){
|
||||||
Write-Host "$($Program.winget) installed successfully."
|
Write-Host "$($Program.winget) installed successfully."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if ($status -eq -1978335189){
|
||||||
|
Write-Host "$($Program.winget) No applicable update found"
|
||||||
|
continue
|
||||||
|
}
|
||||||
Write-Host "Attempt with User scope"
|
Write-Host "Attempt with User scope"
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode
|
||||||
if($status -eq 0){
|
if($status -eq 0){
|
||||||
Write-Host "$($Program.winget) installed successfully with User scope."
|
Write-Host "$($Program.winget) installed successfully with User scope."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if ($status -eq -1978335189){
|
||||||
|
Write-Host "$($Program.winget) No applicable update found"
|
||||||
|
continue
|
||||||
|
}
|
||||||
Write-Host "Attempt with User prompt"
|
Write-Host "Attempt with User prompt"
|
||||||
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program.winget) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
|
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program.winget) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
|
||||||
if ($userChoice -eq 'Yes') {
|
if ($userChoice -eq 'Yes') {
|
||||||
$getcreds = Get-Credential
|
$getcreds = Get-Credential
|
||||||
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru
|
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru -NoNewWindow
|
||||||
Wait-Process -Id $process.Id
|
Wait-Process -Id $process.Id
|
||||||
$status = $process.ExitCode
|
$status = $process.ExitCode
|
||||||
} else {
|
} else {
|
||||||
@ -60,6 +68,10 @@ Function Install-WinUtilProgramWinget {
|
|||||||
Write-Host "$($Program.winget) installed successfully with User prompt."
|
Write-Host "$($Program.winget) installed successfully with User prompt."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if ($status -eq -1978335189){
|
||||||
|
Write-Host "$($Program.winget) No applicable update found"
|
||||||
|
continue
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Failed to install $($Program.winget). With winget"
|
Write-Host "Failed to install $($Program.winget). With winget"
|
||||||
$failedPackages += $($Program.winget)
|
$failedPackages += $($Program.winget)
|
||||||
@ -68,7 +80,7 @@ Function Install-WinUtilProgramWinget {
|
|||||||
if($manage -eq "Uninstalling"){
|
if($manage -eq "Uninstalling"){
|
||||||
# Uninstall package via ID using winget directly.
|
# Uninstall package via ID using winget directly.
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru -NoNewWindow).ExitCode
|
||||||
if($status -ne 0){
|
if($status -ne 0){
|
||||||
Write-Host "Failed to uninstall $($Program.winget)."
|
Write-Host "Failed to uninstall $($Program.winget)."
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user