mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-29 01:11:30 -06:00
- Changed how WinGet installs and uninstalls are handled, by utilizing and .
This commit is contained in:
parent
4a7c8a35bf
commit
16eb61b431
@ -1,7 +1,6 @@
|
|||||||
Function Install-WinUtilProgramWinget {
|
Function Install-WinUtilProgramWinget {
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Manages the provided programs using Winget
|
Manages the provided programs using Winget
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ Function Install-WinUtilProgramWinget {
|
|||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
The triple quotes are required any time you need a " in a normal script block.
|
The triple quotes are required any time you need a " in a normal script block.
|
||||||
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
@ -30,18 +28,37 @@ Function Install-WinUtilProgramWinget {
|
|||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
||||||
if($manage -eq "Installing"){
|
if($manage -eq "Installing"){
|
||||||
# --scope=machine when installing non-UWP apps with winget fails with error code 0x80070005.
|
# Install package via ID, if it fails try again with different scope.
|
||||||
# Removed argument while testing new Winget install method.
|
# Install-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the install.
|
||||||
# Open issue on winget-cli github repo: https://github.com/microsoft/winget-cli/issues/3936
|
$status=$((Install-WinGetPackage -Id $Program -Scope SystemOrUnknown -Mode Silent -AcceptPackageAgreement -AcceptSourceAgreement).Status)
|
||||||
Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --silent $Program" -NoNewWindow -Wait
|
if($status -ne "Ok"){
|
||||||
|
$status=$((Install-WinGetPackage -Id $Program -Scope UserOrUnknown -Mode Silent -AcceptPackageAgreement -AcceptSourceAgreement).Status)
|
||||||
|
if($status -ne "Ok"){
|
||||||
|
$status=$((Install-WinGetPackage -Id $Program -Scope Any -Mode Silent -AcceptPackageAgreement -AcceptSourceAgreement).Status)
|
||||||
|
if($status -ne "Ok"){
|
||||||
|
Write-Host "Failed to install $Program."
|
||||||
|
} else {
|
||||||
|
Write-Host "$Program installed successfully."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "$Program installed successfully."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "$Program installed successfully."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if($manage -eq "Uninstalling"){
|
if($manage -eq "Uninstalling"){
|
||||||
Start-Process -FilePath winget -ArgumentList "uninstall -e --accept-source-agreements --purge --force --silent $Program" -NoNewWindow -Wait
|
# Uninstall package via ID.
|
||||||
}
|
# Uninstall-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the uninstall.
|
||||||
|
$status=$((Uninstall-WinGetPackage -Id $Program -Mode Silent -AcceptSourceAgreement).Status)
|
||||||
|
if ("$status" -ne "Ok") {
|
||||||
|
Write-Host "Failed to uninstall $Program."
|
||||||
|
} else {
|
||||||
|
Write-Host "$Program uninstalled successfully."
|
||||||
|
}
|
||||||
|
}
|
||||||
$X++
|
$X++
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||||
|
}
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user