Skip to content

Instantly share code, notes, and snippets.

@atnbueno
Last active June 1, 2023 18:48
Show Gist options
  • Save atnbueno/207f33325f5b13bd8cb43a98af5bc6a4 to your computer and use it in GitHub Desktop.
Save atnbueno/207f33325f5b13bd8cb43a98af5bc6a4 to your computer and use it in GitHub Desktop.
AutoHotkey script to upgrade everything winget can upgrade, but interactively and with pinned (non-upgradeable) programs
; winget.ahk 1.0.220124 (c) 2022 by u/atnbueno. MIT License.
PinnedPrograms := "iTunes,Mp3tag" ; programs I don't want to upgrade
RunWait, % ComSpec " /c winget list>winget_list.txt", % "C:\Users\" A_UserName, Hide
Loop, Read, % "C:\Users\" A_UserName "\winget_list.txt"
{
If (A_LoopReadLine ~= "winget$")
{
Pinned := False
Loop, Parse, PinnedPrograms, CSV
{
If (A_LoopReadLine ~= A_LoopField)
Pinned := True
}
If (Pinned)
Continue
ProgramName := Trim(SubStr(A_LoopReadLine, 1, 20))
ProgramId := Trim(SubStr(A_LoopReadLine, 41, 41))
InstalledVersion := Trim(SubStr(A_LoopReadLine, 82, 19))
NewVersion := Trim(SubStr(A_LoopReadLine, 101, 13))
If (NewVersion != "") {
MsgBox, % 3+32, % winget upgrade --all, % "Update " ProgramName " from version " InstalledVersion " to " NewVersion "?"
IfMsgBox Yes
{
RunWait, % "winget upgrade -e -h --id " ProgramId
if ErrorLevel
{
MsgBox, % 4+16, % ERROR, % ProgramName " could not be upgraded. Should I try to uninstall it and reinstall it?"
IfMsgBox Yes
{
RunWait, % "winget uninstall -e --id " ProgramId
if ErrorLevel
{
MsgBox, % 4+16, % ERROR, % ProgramName " could not be uninstalled. Continue with next program?"
IfMsgBox Yes
Continue
ExitApp
}
RunWait, % "winget install -e --id " ProgramId
if ErrorLevel
{
MsgBox, % 4+16, % ERROR, % ProgramName " could not be reinstalled. Continue with next program?"
IfMsgBox No
ExitApp
}
}
}
}
IfMsgBox Cancel
ExitApp
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment