Fix ALL Program Installs (#1856)

* Compile Winutil

* Update Invoke-WPFOOSU

* Compile Winutil

* Modify Winget program installs

did a waterfall type installer. First trys systemwide at admin prompt, then user scope, then unelevated with no scope.
This should fix ALL program installs.

* Compile Winutil

---------

Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
This commit is contained in:
Chris Titus 2024-04-20 21:48:55 -05:00 committed by GitHub
parent 9ef050442d
commit 2354645b47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 46 deletions

View File

@ -28,39 +28,46 @@ 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"){
# Install package via ID, if it fails try again with different scope. # Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
# Install-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the install. # Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
# With WinGet, not all installers honor any of the following: System-wide or User Installs OR Silent Install Mode. # Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
# 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.
$status=$((Install-WinGetPackage -Id $Program -Scope SystemOrUnknown -Mode Silent -Source winget -MatchOption Equals).Status) try {
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
Write-Host "Not System" if($status -ne 0){
$status=$((Install-WinGetPackage -Id $Program -Scope UserOrUnknown -Mode Silent -Source winget -MatchOption Equals).Status) Write-Host "Attempt with User scope"
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
Write-Host "Not User" if($status -ne 0){
$status=$((Install-WinGetPackage -Id $Program -Scope Any -Mode Silent -Source winget -MatchOption Equals).Status) Write-Host "Attempt with Unelevated prompt"
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
Write-Host "Failed to install $Program." if($status -ne 0){
Write-Host "Failed to install $Program."
} else {
Write-Host "$Program installed successfully with Unelevated prompt."
}
} else { } else {
Write-Host "$Program installed successfully." Write-Host "$Program installed successfully with User scope."
} }
} else { } else {
Write-Host "$Program installed successfully." Write-Host "$Program installed successfully."
} }
} else { } catch {
Write-Host "$Program installed successfully." Write-Host "Failed to install $Program due to an error: $_"
} }
} }
if($manage -eq "Uninstalling"){ if($manage -eq "Uninstalling"){
# Uninstall package via ID. # Uninstall package via ID using winget directly.
# Uninstall-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the uninstall. try {
$status=$((Uninstall-WinGetPackage -Id $Program -Mode Silent -MatchOption Equals -Source winget).Status) $status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $Program --silent" -Wait -PassThru).ExitCode
if ("$status" -ne "Ok") { if($status -ne 0){
Write-Host "Failed to uninstall $Program." Write-Host "Failed to uninstall $Program."
} else { } else {
Write-Host "$Program uninstalled successfully." Write-Host "$Program uninstalled successfully."
}
} catch {
Write-Host "Failed to uninstall $Program due to an error: $_"
} }
} }
$X++ $X++
} }

View File

@ -727,39 +727,46 @@ 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"){
# Install package via ID, if it fails try again with different scope. # Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
# Install-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the install. # Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
# With WinGet, not all installers honor any of the following: System-wide or User Installs OR Silent Install Mode. # Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
# 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.
$status=$((Install-WinGetPackage -Id $Program -Scope SystemOrUnknown -Mode Silent -Source winget -MatchOption Equals).Status) try {
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
Write-Host "Not System" if($status -ne 0){
$status=$((Install-WinGetPackage -Id $Program -Scope UserOrUnknown -Mode Silent -Source winget -MatchOption Equals).Status) Write-Host "Attempt with User scope"
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
Write-Host "Not User" if($status -ne 0){
$status=$((Install-WinGetPackage -Id $Program -Scope Any -Mode Silent -Source winget -MatchOption Equals).Status) Write-Host "Attempt with Unelevated prompt"
if($status -ne "Ok"){ $status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
Write-Host "Failed to install $Program." if($status -ne 0){
Write-Host "Failed to install $Program."
} else {
Write-Host "$Program installed successfully with Unelevated prompt."
}
} else { } else {
Write-Host "$Program installed successfully." Write-Host "$Program installed successfully with User scope."
} }
} else { } else {
Write-Host "$Program installed successfully." Write-Host "$Program installed successfully."
} }
} else { } catch {
Write-Host "$Program installed successfully." Write-Host "Failed to install $Program due to an error: $_"
} }
} }
if($manage -eq "Uninstalling"){ if($manage -eq "Uninstalling"){
# Uninstall package via ID. # Uninstall package via ID using winget directly.
# Uninstall-WinGetPackage always returns "InstallerErrorCode" 0, so we have to check the "Status" of the uninstall. try {
$status=$((Uninstall-WinGetPackage -Id $Program -Mode Silent -MatchOption Equals -Source winget).Status) $status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $Program --silent" -Wait -PassThru).ExitCode
if ("$status" -ne "Ok") { if($status -ne 0){
Write-Host "Failed to uninstall $Program." Write-Host "Failed to uninstall $Program."
} else { } else {
Write-Host "$Program uninstalled successfully." Write-Host "$Program uninstalled successfully."
}
} catch {
Write-Host "Failed to uninstall $Program due to an error: $_"
} }
} }
$X++ $X++
} }