From c49bd0b1039d08ff7c9f6d823b35322f63c27207 Mon Sep 17 00:00:00 2001 From: Allen Houchins Date: Tue, 24 Nov 2026 00:14:46 -0600 Subject: [PATCH 1/2] Install DevToys, Webex and Docker Desktop where users can run them All three installed into the SYSTEM account's profile, or not at all, because Fleet runs install scripts as SYSTEM. - DevToys has no machine-wide mode (Inno DefaultDirName is {userpf}), so install and uninstall now run as the signed-in user via a scheduled task, and the uninstall searches every user hive. - Webex's MSI defaults to a per-user install; force ALLUSERS=1 and clear MSIINSTALLPERUSER, and remove a stranded SYSTEM-profile copy first. - Docker Desktop refuses "install --user" from SYSTEM outright; use the all-users install and poll HKLM for the registration. --- .../inputs/winget/scripts/devtoys_install.ps1 | 110 ++++- .../winget/scripts/devtoys_uninstall.ps1 | 384 ++++++++++++++++-- .../inputs/winget/scripts/docker_install.ps1 | 47 ++- .../inputs/winget/scripts/webex_install.ps1 | 50 +++ ee/maintained-apps/inputs/winget/webex.json | 5 +- .../outputs/devtoys/windows.json | 8 +- .../outputs/docker/windows.json | 4 +- ee/maintained-apps/outputs/webex/windows.json | 4 +- 8 files changed, 537 insertions(+), 75 deletions(-) create mode 100644 ee/maintained-apps/inputs/winget/scripts/webex_install.ps1 diff --git a/ee/maintained-apps/inputs/winget/scripts/devtoys_install.ps1 b/ee/maintained-apps/inputs/winget/scripts/devtoys_install.ps1 index 268199c2aac..98224b210e2 100644 --- a/ee/maintained-apps/inputs/winget/scripts/devtoys_install.ps1 +++ b/ee/maintained-apps/inputs/winget/scripts/devtoys_install.ps1 @@ -1,30 +1,112 @@ # Learn more about .exe install scripts: # http://fleetdm.com/learn-more-about/exe-install-scripts # -# This app ships as an Inno Setup installer. +# DevToys ships as an Inno Setup installer whose install directory is +# {userpf}\DevToys Preview, so it installs per user and has no machine-wide +# mode. Installing it from this script's SYSTEM context would put it in +# SYSTEM's profile where nobody can launch it. Run the installer as the +# signed-in user instead. $exeFilePath = "${env:INSTALLER_PATH}" +$taskName = "fleet-install-devtoys" +$taskRunning = 267009 # SCHED_S_TASK_RUNNING +$exitCode = 0 +$stageDir = $null try { - if (-not (Test-Path $exeFilePath)) { - Write-Host "Error: Installer file not found at: $exeFilePath" - Exit 1 + $owner = Get-CimInstance Win32_Process -Filter 'name = "explorer.exe"' -ErrorAction SilentlyContinue | + Invoke-CimMethod -MethodName GetOwner -ErrorAction SilentlyContinue | + Where-Object { $_.User } | + Select-Object -First 1 + if (-not $owner) { + Throw "DevToys installs per user and no user is signed in to this host. Sign in and try again." } + $userAccount = "$($owner.Domain)\$($owner.User)" + $sid = (New-Object System.Security.Principal.NTAccount($userAccount)).Translate( + [System.Security.Principal.SecurityIdentifier]).Value + Write-Host "Installing DevToys for $userAccount." - $processOptions = @{ - FilePath = "$exeFilePath" - ArgumentList = "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART" - PassThru = $true - Wait = $true - NoNewWindow = $true + # Setup can't close a running DevToys from the scheduled task's logon session, + # so it would wait on a "files in use" prompt until this script times out. + # Stop what's running from the user's install first. + $profilePath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid" -ErrorAction SilentlyContinue).ProfileImagePath + if ($profilePath) { + $appDir = Join-Path $profilePath "AppData\Local\Programs\DevToys Preview" + $isAppProcess = { $_.Path -and $_.Path.StartsWith("$appDir\", [System.StringComparison]::OrdinalIgnoreCase) } + $running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object $isAppProcess) + if ($running.Count) { + Write-Host "Stopping DevToys: $(($running | ForEach-Object { "$($_.Name) ($($_.Id))" }) -join ', ')" + # Windows reuses PIDs, so match the start time too. + $stopped = @($running | ForEach-Object { "$($_.Id)|$($_.StartTime.Ticks)" }) + $running | Stop-Process -Force -ErrorAction SilentlyContinue + for ($waited = 0; $waited -lt 30; $waited++) { + Start-Sleep -Seconds 1 + $running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object $isAppProcess | + Where-Object { $stopped -contains "$($_.Id)|$($_.StartTime.Ticks)" }) + if ($running.Count -eq 0) { break } + } + if ($running.Count) { + Throw "DevToys is still running ($(($running | ForEach-Object { "$($_.Name) ($($_.Id))" }) -join ', ')) and Setup can't replace it. Quit it and try again." + } + } } - $process = Start-Process @processOptions - $exitCode = $process.ExitCode + # Fleet's installer directory is not readable by that user, so stage a copy in + # a new folder only SYSTEM and Administrators can write to. + $security = New-Object System.Security.AccessControl.DirectorySecurity + $security.SetAccessRuleProtection($true, $false) + foreach ($grant in @(@("S-1-5-18", "FullControl"), @("S-1-5-32-544", "FullControl"), @($sid, "ReadAndExecute"))) { + $security.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule( + (New-Object System.Security.Principal.SecurityIdentifier($grant[0])), $grant[1], + "ContainerInherit, ObjectInherit", "None", "Allow"))) + } + $stageDir = Join-Path $env:ProgramData ("fleet-devtoys-" + [guid]::NewGuid().ToString("N")) + [void][System.IO.Directory]::CreateDirectory($stageDir, $security) + $stagedInstaller = Join-Path $stageDir (Split-Path $exeFilePath -Leaf) + Copy-Item -LiteralPath $exeFilePath -Destination $stagedInstaller -Force -ErrorAction Stop + + # Inno Setup: /VERYSILENT runs without any UI (the NSIS /S switch does nothing). + $action = New-ScheduledTaskAction -Execute $stagedInstaller -Argument "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART" + $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries + $principal = New-ScheduledTaskPrincipal -UserId $userAccount + $task = New-ScheduledTask -Action $action -Settings $settings -Principal $principal + Register-ScheduledTask -TaskName $taskName -InputObject $task -Force -ErrorAction Stop | Out-Null + + $startDate = Get-Date + $lastRun = (Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop).LastRunTime + Start-ScheduledTask -TaskName $taskName -ErrorAction Stop + + # Wait for a result rather than for the "Running" state, which a fast task can + # enter and leave between polls. A task that's still queued hasn't updated + # LastRunTime yet. + Start-Sleep -Seconds 2 + while ($true) { + $info = Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop + $state = (Get-ScheduledTask -TaskName $taskName -ErrorAction Stop).State + if ($info.LastRunTime -ne $lastRun -and $state -ne "Running" -and $info.LastTaskResult -ne $taskRunning) { + $exitCode = $info.LastTaskResult + break + } + if ((New-TimeSpan -Start $startDate).TotalSeconds -gt 900) { + Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue + Throw "Timed out waiting for the install task to finish." + } + Start-Sleep -Seconds 5 + } Write-Host "Install exit code: $exitCode" - Exit $exitCode } catch { Write-Host "Error: $_" - Exit 1 + $exitCode = 1 +} finally { + if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) { + Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue + } + if ($stageDir -and (Test-Path -LiteralPath $stageDir)) { + Remove-Item -LiteralPath $stageDir -Recurse -Force -ErrorAction SilentlyContinue + } } + +# Exit turns a code above Int32.MaxValue, such as a task's HRESULT, into 0. +if ($exitCode -gt [int]::MaxValue) { $exitCode = 1 } +Exit $exitCode diff --git a/ee/maintained-apps/inputs/winget/scripts/devtoys_uninstall.ps1 b/ee/maintained-apps/inputs/winget/scripts/devtoys_uninstall.ps1 index 870201ba3af..fa18a459adf 100644 --- a/ee/maintained-apps/inputs/winget/scripts/devtoys_uninstall.ps1 +++ b/ee/maintained-apps/inputs/winget/scripts/devtoys_uninstall.ps1 @@ -1,39 +1,349 @@ -$displayName = "DevToys" -$publisher = "DevToys" -$paths = @( - 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', - 'HKCU:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall', - 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', - 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall' -) -$uninstall = $null -foreach ($p in $paths) { - $items = Get-ItemProperty "$p\*" -ErrorAction SilentlyContinue | Where-Object { - $_.DisplayName -and ($_.DisplayName -eq $displayName -or $_.DisplayName -like "$displayName *") -and - ($publisher -eq "" -or $_.Publisher -like "*$publisher*") - } - if ($items) { $uninstall = $items | Select-Object -First 1; break } +# DevToys installs per user, so its uninstall entry is in the installing user's +# registry hive rather than SYSTEM's, and Inno Setup's uninstaller removes the +# install directory recorded in the hive of whoever runs it -- run as SYSTEM +# against a user's install it would miss that user's copy. So search every hive +# and run the uninstaller as the user who owns the entry. A copy belonging to a +# user who isn't signed in can't be removed and fails the uninstall. + +$displayNamePattern = '^DevToys\s' +$publisher = "DevToys" +$taskName = "fleet-uninstall-devtoys" +$appDir = "AppData\Local\Programs\DevToys Preview" # in each user's profile +$taskRunning = 267009 # SCHED_S_TASK_RUNNING +$timeoutSeconds = 300 +$exitCode = 0 + +function Get-AppEntries { + $roots = [System.Collections.Generic.List[string]]::new() + $roots.Add('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall') + $roots.Add('HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall') + # Only SYSTEM's hive and user hives (S-1-5-21 local or AD, S-1-12-1 Entra ID). + # LocalService and NetworkService can write their own hives, and an entry + # there would run as SYSTEM. + foreach ($hive in (Get-ChildItem 'Registry::HKEY_USERS' -ErrorAction SilentlyContinue)) { + if ($hive.PSChildName -notmatch '^(S-1-5-18|S-1-5-21-[\d-]+|S-1-12-1-[\d-]+)$') { continue } + $roots.Add("Registry::$($hive.Name)\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") + $roots.Add("Registry::$($hive.Name)\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall") + } + + $entries = @() + foreach ($root in $roots) { + foreach ($sub in (Get-ChildItem -Path $root -ErrorAction SilentlyContinue)) { + $key = Get-ItemProperty $sub.PSPath -ErrorAction SilentlyContinue + if (-not $key.DisplayName) { continue } + # Some installers pad these values with nulls (Fork writes "Fork" + 15 of them). + $name = ($key.DisplayName -replace "`0", "").Trim() + if ($name -notmatch $displayNamePattern) { continue } + if (($key.Publisher -replace "`0", "").Trim() -ne $publisher) { continue } + + # Only a real user's entry needs the uninstaller run for them; HKLM and + # SYSTEM's hive are already in the right context. + $sid = $null + if ($sub.PSPath -match 'HKEY_USERS\\(S-1-5-21-[\d-]+|S-1-12-1-[\d-]+)\\') { $sid = $matches[1] } + + $entries += [PSCustomObject]@{ + DisplayName = $name + KeyPath = $sub.PSPath + Sid = $sid + Command = if ($key.QuietUninstallString) { $key.QuietUninstallString } else { $key.UninstallString } + } + } + } + return $entries } -if (-not $uninstall -or -not $uninstall.UninstallString) { Write-Host "Uninstall entry not found"; Exit 0 } -$uninstallString = $uninstall.UninstallString -$exePath = "" -if ($uninstallString -match '^"([^"]+)"(.*)') { $exePath = $matches[1] } -elseif ($uninstallString -match '^(.+?\.exe)(.*)$') { $exePath = $matches[1] } -else { Write-Host "Error: Could not parse uninstall string: $uninstallString"; Exit 1 } -$installDir = if ($uninstall.InstallLocation -and (Test-Path -LiteralPath $uninstall.InstallLocation)) { $uninstall.InstallLocation.TrimEnd('\') } else { (Split-Path -Parent $exePath).TrimEnd('\') } -$argumentList = @("/VERYSILENT", "/NORESTART") + +# Registry hives of users who aren't signed in aren't loaded, so find their +# copies by the app folder in their profiles instead. +function Get-SignedOutInstalls { + foreach ($profileKey in (Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -ErrorAction SilentlyContinue)) { + $sid = $profileKey.PSChildName + if ($sid -notmatch '^S-1-(5-21|12-1)-[\d-]+$' -or (Test-Path "Registry::HKEY_USERS\$sid")) { continue } + $profilePath = (Get-ItemProperty $profileKey.PSPath -ErrorAction SilentlyContinue).ProfileImagePath + if (-not $profilePath) { continue } + if (-not (Test-Path -LiteralPath (Join-Path $profilePath "$appDir\DevToys.exe"))) { continue } + try { + (New-Object System.Security.Principal.SecurityIdentifier($sid)).Translate([System.Security.Principal.NTAccount]).Value + } catch { + $sid + } + } +} + +function Resolve-Uninstaller { + param([string]$Command) + + $exePath = "" + $arguments = "" + if ($Command -match '^\s*"([^"]+)"\s*(.*)$') { + $exePath = $matches[1] + $arguments = $matches[2].Trim() + } elseif ($Command -match '(?i)^\s*(.+?\.exe)\s*(.*)$') { + $exePath = $matches[1] + $arguments = $matches[2].Trim() + } + + # A user's entry could point at a share that collects the computer account's + # credentials, so only a drive-letter path is touched as SYSTEM. PowerShell + # also reaches a share without a leading \\, as FileSystem::\\host\share. + if ($exePath -and $exePath -notmatch '^[A-Za-z]:[\\/]') { return $null } + + # A 32-bit installer run as SYSTEM is redirected into SysWOW64, but records the + # unredirected system32 path that 64-bit PowerShell cannot resolve. + if ($exePath -and -not (Test-Path -LiteralPath $exePath)) { + $redirected = $exePath -replace '(?i)\\system32\\', '\SysWOW64\' + if ($redirected -ne $exePath -and (Test-Path -LiteralPath $redirected)) { + Write-Host " Uninstaller is under SysWOW64, not the recorded $exePath" + $exePath = $redirected + } + } + + # Inno Setup: /VERYSILENT runs without any UI; the registered QuietUninstallString + # uses /SILENT, which still shows a progress window nobody can see or dismiss. + $arguments = ($arguments -replace '(?i)(^|\s)/(VERY)?SILENT(?=$|\s)', ' ').Trim() + $arguments = "$arguments /VERYSILENT /SUPPRESSMSGBOXES /NORESTART".Trim() + + return [PSCustomObject]@{ ExePath = $exePath; Arguments = $arguments } +} + +function Invoke-AsUser { + param([string]$Sid, [string]$ExePath, [string]$Arguments) + + $account = (New-Object System.Security.Principal.SecurityIdentifier($Sid)).Translate( + [System.Security.Principal.NTAccount]).Value + Write-Host " Running as ${account}: $ExePath $Arguments" + + try { + $action = New-ScheduledTaskAction -Execute $ExePath -Argument $Arguments + $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries + $principal = New-ScheduledTaskPrincipal -UserId $account + $task = New-ScheduledTask -Action $action -Settings $settings -Principal $principal + Register-ScheduledTask -TaskName $taskName -InputObject $task -Force -ErrorAction Stop | Out-Null + + $startDate = Get-Date + $lastRun = (Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop).LastRunTime + Start-ScheduledTask -TaskName $taskName -ErrorAction Stop + + # Wait for a result rather than for the "Running" state, which a fast task can + # enter and leave between polls. A task that's still queued hasn't updated + # LastRunTime yet. + Start-Sleep -Seconds 2 + while ($true) { + $info = Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop + $state = (Get-ScheduledTask -TaskName $taskName -ErrorAction Stop).State + if ($info.LastRunTime -ne $lastRun -and $state -ne "Running" -and $info.LastTaskResult -ne $taskRunning) { + return $info.LastTaskResult + } + if ((New-TimeSpan -Start $startDate).TotalSeconds -gt $timeoutSeconds) { + Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue + Write-Host " Timed out waiting for the task to finish." + return 1460 # ERROR_TIMEOUT + } + Start-Sleep -Seconds 5 + } + } finally { + if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) { + Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue + } + } +} + +# A user can write to their own profile, including swapping a folder for a link +# elsewhere, so their folder is removed as them rather than as SYSTEM. cmd +# expands %VAR% even inside quotes, so a path containing % is never passed to it. +function Remove-AppDir { + param([string]$Path, [string]$Sid) + + if ($Sid -and $Path.Contains('%')) { + Write-Host " Could not remove $Path." + return $false + } + if ($Sid) { + try { + $null = Invoke-AsUser -Sid $Sid -ExePath "$env:SystemRoot\System32\cmd.exe" -Arguments "/d /c rd /s /q `"$Path`"" + } catch { + Write-Host " $_" + } + } else { + Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue + } + if (Test-Path -LiteralPath $Path) { + Write-Host " Could not remove $Path." + return $false + } + return $true +} + +# Shortcuts the uninstaller didn't get to. Match on where they point rather than on +# a filename, which also catches the vendor subfolders some installers create. Read +# as SYSTEM, a user's shortcut resolves its target through SYSTEM's profile, so the +# working directory is checked too, and only the owning profile is searched. A +# user's shortcuts are deleted as that user, like their folder. +function Remove-Shortcuts { + param([string]$Dir, [string]$ProfilePath, [string]$Sid) + + if ($ProfilePath) { + $roots = @((Join-Path $ProfilePath 'AppData\Roaming\Microsoft\Windows\Start Menu\Programs'), (Join-Path $ProfilePath 'Desktop')) + } else { + $roots = @('Programs', 'Desktop', 'CommonPrograms', 'CommonDesktopDirectory') | ForEach-Object { [Environment]::GetFolderPath($_) } + } + $found = @() + $shell = New-Object -ComObject WScript.Shell + foreach ($root in $roots) { + if (-not $root -or -not (Test-Path -LiteralPath $root)) { continue } + foreach ($lnk in (Get-ChildItem -LiteralPath $root -Filter '*.lnk' -Recurse -ErrorAction SilentlyContinue)) { + try { $link = $shell.CreateShortcut($lnk.FullName) } catch { continue } + foreach ($path in @($link.TargetPath, $link.WorkingDirectory)) { + if ($path -and ($path -eq $Dir -or $path.StartsWith("$Dir\", [System.StringComparison]::OrdinalIgnoreCase))) { + $found += $lnk.FullName + break + } + } + } + } + if (-not $found) { return } + if ($Sid) { + $quoted = ($found | Where-Object { -not $_.Contains('%') } | ForEach-Object { "`"$_`"" }) -join ' ' + if ($quoted) { + try { + $null = Invoke-AsUser -Sid $Sid -ExePath "$env:SystemRoot\System32\cmd.exe" -Arguments "/d /c del /f /q $quoted" + } catch { + Write-Host " $_" + } + } + } else { + $found | ForEach-Object { Remove-Item -LiteralPath $_ -Force -ErrorAction SilentlyContinue } + } + $found | Where-Object { Test-Path -LiteralPath $_ } | ForEach-Object { Write-Host " Could not remove shortcut $_." } +} + try { - $processOptions = @{ FilePath = $exePath; ArgumentList = $argumentList; NoNewWindow = $true; PassThru = $true; Wait = $true } - $process = Start-Process @processOptions - $exitCode = $process.ExitCode - Write-Host "Uninstall exit code: $exitCode" - # Only sweep leftovers on a successful uninstall, and never a root/short path - if ($exitCode -eq 0 -and $installDir) { - $resolvedDir = $null - try { $resolvedDir = (Resolve-Path -LiteralPath $installDir -ErrorAction Stop).Path } catch { $resolvedDir = $null } - if ($resolvedDir -and ($resolvedDir -match '^[A-Za-z]:\\') -and ((($resolvedDir.TrimEnd('\')) -split '\\').Count -ge 3) -and (Test-Path -LiteralPath $resolvedDir)) { - Remove-Item -LiteralPath $resolvedDir -Recurse -Force -ErrorAction SilentlyContinue - } - } - Exit $exitCode -} catch { Write-Host "Error running uninstaller: $_"; Exit 1 } + $entries = @(Get-AppEntries) + + foreach ($entry in $entries) { + Write-Host "Removing '$($entry.DisplayName)' ($($entry.KeyPath))" + $uninstaller = Resolve-Uninstaller $entry.Command + if (-not $uninstaller) { + Write-Host " Skipping this copy: its uninstaller isn't on a local drive." + if ($exitCode -eq 0) { $exitCode = 1 } + continue + } + $hasUninstaller = $uninstaller.ExePath -and (Test-Path -LiteralPath $uninstaller.ExePath) + + # A user's uninstall string comes from a hive that user can write to, so only + # touch the app's folder in that user's own profile. + $installDir = "" + if ($uninstaller.ExePath) { try { $installDir = [System.IO.Path]::GetFullPath((Split-Path $uninstaller.ExePath -Parent)) } catch {} } + # Resolve-Uninstaller redirects only an uninstaller it can find, so without one + # a 32-bit installer's SYSTEM-profile copy still points into system32. + if (-not $entry.Sid -and $installDir -and -not (Test-Path -LiteralPath $installDir)) { + $redirected = $installDir -replace '(?i)\\system32\\', '\SysWOW64\' + if (Test-Path -LiteralPath $redirected) { $installDir = $redirected } + } + $isAppDir = $installDir -and (Split-Path $installDir -Leaf) -eq (Split-Path $appDir -Leaf) + $profilePath = $null + if ($entry.Sid) { + $profilePath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$($entry.Sid)" -ErrorAction SilentlyContinue).ProfileImagePath + $userAppDir = if ($profilePath) { Join-Path $profilePath $appDir } else { "" } + if (-not $hasUninstaller) { $installDir = $userAppDir } + $isAppDir = $userAppDir -and $installDir -eq $userAppDir + } + + if ($isAppDir) { + # Anything running out of this install directory blocks removal. Matching on the + # directory rather than a process name keeps another install of the same app, + # in another user's profile, running. + Get-Process -ErrorAction SilentlyContinue | + Where-Object { $_.Path -and $_.Path.StartsWith("$installDir\", [System.StringComparison]::OrdinalIgnoreCase) } | + Stop-Process -Force -ErrorAction SilentlyContinue + } + + if (-not $hasUninstaller) { + Write-Host " Uninstaller is missing; removing what's left of this copy." + if ($installDir -and (Test-Path -LiteralPath $installDir) -and + -not ($isAppDir -and (Remove-AppDir $installDir $entry.Sid))) { + Write-Host " Leaving this copy registered because $installDir is still there." + if ($exitCode -eq 0) { $exitCode = 1 } + continue + } + if ($isAppDir) { Remove-Shortcuts $installDir $profilePath $entry.Sid } + Remove-Item -Path $entry.KeyPath -Recurse -Force -ErrorAction SilentlyContinue + continue + } + + # Caught here so one copy's failure doesn't skip the others. + try { + if ($entry.Sid) { + $result = Invoke-AsUser -Sid $entry.Sid -ExePath $uninstaller.ExePath -Arguments $uninstaller.Arguments + } else { + Write-Host " Uninstall command: $($uninstaller.ExePath) $($uninstaller.Arguments)" + $process = Start-Process -FilePath $uninstaller.ExePath -ArgumentList $uninstaller.Arguments ` + -NoNewWindow -PassThru -ErrorAction Stop + $null = $process.Handle # keeps ExitCode readable after the process exits + if ($process.WaitForExit($timeoutSeconds * 1000)) { + $result = $process.ExitCode + } else { + Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue + Write-Host " Timed out waiting for the uninstaller to finish." + $result = 1460 # ERROR_TIMEOUT + } + } + } catch { + Write-Host " Could not run the uninstaller: $_" + $result = 1 + } + Write-Host " Uninstall exit code: $result" + if ($result -ne 0) { + Write-Host " Leaving this copy registered so the uninstall can be retried." + if ($exitCode -eq 0) { $exitCode = $result } + continue + } + + # An uninstaller that relaunches itself from %TEMP% exits while removal is + # still in flight. Either the directory or the registration going away means + # it got there. + for ($waited = 0; $waited -lt 60; $waited++) { + if (-not (Test-Path -LiteralPath $installDir)) { break } + if (-not (Get-ItemProperty $entry.KeyPath -ErrorAction SilentlyContinue)) { + Start-Sleep -Seconds 3 + break + } + Start-Sleep -Seconds 1 + } + + if ($isAppDir -and (Test-Path -LiteralPath $installDir)) { + Write-Host " Uninstaller left $installDir behind; removing it." + if (-not (Remove-AppDir $installDir $entry.Sid)) { + if ($exitCode -eq 0) { $exitCode = 1 } + continue + } + } + if ($isAppDir) { Remove-Shortcuts $installDir $profilePath $entry.Sid } + + if (Get-ItemProperty $entry.KeyPath -ErrorAction SilentlyContinue) { + Remove-Item -Path $entry.KeyPath -Recurse -Force -ErrorAction SilentlyContinue + } + } + + $remaining = @(Get-AppEntries) + $signedOut = @(Get-SignedOutInstalls) + if ($remaining.Count -gt 0) { + Write-Host "WARNING: $($remaining.Count) DevToys registration(s) still present:" + $remaining | ForEach-Object { Write-Host " - $($_.DisplayName) [$($_.KeyPath)]" } + if ($exitCode -eq 0) { $exitCode = 1 } + } + if ($signedOut.Count -gt 0) { + Write-Host "DevToys is still installed for users who aren't signed in: $($signedOut -join ', '). Run the uninstall again while they're signed in." + if ($exitCode -eq 0) { $exitCode = 1 } + } + if ($exitCode -eq 0) { + if ($entries.Count) { Write-Host "DevToys removed." } else { Write-Host "DevToys is not installed." } + } + +} catch { + Write-Host "Error running uninstaller: $_" + $exitCode = 1 +} + +# Exit turns a code above Int32.MaxValue, such as a task's HRESULT, into 0. +if ($exitCode -gt [int]::MaxValue) { $exitCode = 1 } +Exit $exitCode diff --git a/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 b/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 index 4019be4c04a..4774394a5da 100644 --- a/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 +++ b/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 @@ -1,32 +1,49 @@ # Learn more about .exe install scripts: # http://fleetdm.com/learn-more-about/exe-install-scripts +# +# Docker Desktop refuses "install --user" when it is run by the SYSTEM account, +# because that would install it into the SYSTEM profile. Run the all-users +# install instead: it needs administrator rights, puts the app in +# C:\Program Files\Docker\Docker and registers it in HKLM. +# +# Users who need Windows containers or Hyper-V VM management must also be in +# the local docker-users group; the all-users install does not add them. $exeFilePath = "${env:INSTALLER_PATH}" +$registryKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Docker Desktop" try { - # Docker Desktop 4.72+ added a per-user vs all-user install choice for - # Windows. All-user silent installs hang on Windows Server runners - # (Docker Desktop is not officially supported on Windows Server). Install - # per-user with --user instead: no admin needed, target is - # %LOCALAPPDATA%\Programs\DockerDesktop, and uninstall info is written to - # HKCU. --accept-license suppresses the subscription agreement prompt. - Start-Process -FilePath "$exeFilePath" -ArgumentList "install","--user","--accept-license","--quiet" | Out-Null + # --accept-license suppresses the subscription agreement prompt. + $process = Start-Process -FilePath "$exeFilePath" ` + -ArgumentList "install","--accept-license","--quiet" -PassThru + # Touch the handle so ExitCode is still readable after the process exits. + $null = $process.Handle - # The installer process can keep running for several minutes after the - # app is registered with Windows. Poll the HKCU uninstall key (osquery's - # programs table reads both HKLM and HKU) to detect when the core install - # has completed, rather than blocking on Start-Process -Wait. - $registryKey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Docker Desktop" - $deadline = (Get-Date).AddMinutes(4) + # The installer process can keep running for a while after the app is + # registered with Windows, so stop waiting as soon as the registration is + # there rather than blocking on the process. + $deadline = (Get-Date).AddMinutes(8) while ((Get-Date) -lt $deadline) { if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) { - Write-Host "Docker Desktop registered in HKCU." + Write-Host "Docker Desktop registered in HKLM." Exit 0 } + if ($process.HasExited) { + # Registration can land a moment after the installer exits. + Start-Sleep -Seconds 10 + if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) { + Write-Host "Docker Desktop registered in HKLM." + Exit 0 + } + Write-Host "Install exit code: $($process.ExitCode)" + Write-Host "The installer exited without registering Docker Desktop. See C:\ProgramData\DockerDesktop\install-log-admin.txt." + if ($process.ExitCode -eq 0) { Exit 1 } + Exit $process.ExitCode + } Start-Sleep -Seconds 10 } - Write-Host "Docker Desktop did not register within timeout." + Write-Host "Docker Desktop did not register within 8 minutes. See C:\ProgramData\DockerDesktop\install-log-admin.txt." Exit 1 } catch { Write-Host "Error: $_" diff --git a/ee/maintained-apps/inputs/winget/scripts/webex_install.ps1 b/ee/maintained-apps/inputs/winget/scripts/webex_install.ps1 new file mode 100644 index 00000000000..91778c6b24c --- /dev/null +++ b/ee/maintained-apps/inputs/winget/scripts/webex_install.ps1 @@ -0,0 +1,50 @@ +# Learn more about install scripts: +# http://fleetdm.com/learn-more-about/install-scripts +# +# Webex's MSI is a dual-purpose package that defaults to a per-user install +# (ALLUSERS=2, MSIINSTALLPERUSER=1), so under Fleet's SYSTEM context it lands in +# the SYSTEM account's profile, where no one can open it. Force the per-machine +# install into Program Files, which is also what enables the Outlook +# integration. First remove a copy an earlier install left in the SYSTEM +# profile, so it isn't left behind unreachable. + +$logFile = "${env:TEMP}/fleet-install-software.log" +$upgradeCode = '{B9DCA8E9-B3A9-419A-9D6F-9BC3557EE72C}' + +# 3010 = reboot required, 1641 = reboot initiated +$successCodes = @(0, 3010, 1641) + +try { + +$installer = New-Object -ComObject "WindowsInstaller.Installer" + +foreach ($productCode in @($installer.RelatedProducts($upgradeCode))) { + # 0 = installed for this account only; 1 = installed machine-wide + if ($installer.ProductInfo($productCode, "AssignmentType") -ne "0") { continue } + + Write-Host "Removing the copy of Webex in the SYSTEM profile ($productCode)" + $removeProcess = Start-Process msiexec.exe ` + -ArgumentList "/quiet /norestart /x $productCode" ` + -PassThru -Wait + if ($successCodes -notcontains $removeProcess.ExitCode) { + Write-Host "Removal exited $($removeProcess.ExitCode)" + Exit $removeProcess.ExitCode + } +} + +$installProcess = Start-Process msiexec.exe ` + -ArgumentList "/quiet /norestart /lv `"${logFile}`" ALLUSERS=1 MSIINSTALLPERUSER=`"`" /i `"${env:INSTALLER_PATH}`"" ` + -PassThru -Wait + +Get-Content $logFile -Tail 500 + +if ($successCodes -contains $installProcess.ExitCode) { + Exit 0 +} + +Exit $installProcess.ExitCode + +} catch { + Write-Host "Error: $_" + Exit 1 +} diff --git a/ee/maintained-apps/inputs/winget/webex.json b/ee/maintained-apps/inputs/winget/webex.json index 8e95421a418..219d3aeaad7 100644 --- a/ee/maintained-apps/inputs/winget/webex.json +++ b/ee/maintained-apps/inputs/winget/webex.json @@ -6,5 +6,8 @@ "installer_arch": "x64", "installer_type": "msi", "installer_scope": "machine", - "default_categories": ["Communication"] + "install_script_path": "ee/maintained-apps/inputs/winget/scripts/webex_install.ps1", + "default_categories": [ + "Communication" + ] } diff --git a/ee/maintained-apps/outputs/devtoys/windows.json b/ee/maintained-apps/outputs/devtoys/windows.json index f440905d716..78242e058c1 100644 --- a/ee/maintained-apps/outputs/devtoys/windows.json +++ b/ee/maintained-apps/outputs/devtoys/windows.json @@ -8,8 +8,8 @@ "open": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM processes WHERE LOWER(name) = 'devtoys.exe');" }, "installer_url": "https://github.com/DevToys-app/DevToys/releases/download/v2.0.9.0/devtoys_win_x64.exe", - "install_script_ref": "e01b1635", - "uninstall_script_ref": "86a44362", + "install_script_ref": "5d1dabad", + "uninstall_script_ref": "33a84921", "sha256": "e099d9fc6771110c3371bb8adc778312d34ec0963a2f86dee4f7c1661b7e7c0f", "default_categories": [ "Productivity" @@ -17,7 +17,7 @@ } ], "refs": { - "86a44362": "$displayName = \"DevToys\"\n$publisher = \"DevToys\"\n$paths = @(\n 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall',\n 'HKCU:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall',\n 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall',\n 'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall'\n)\n$uninstall = $null\nforeach ($p in $paths) {\n $items = Get-ItemProperty \"$p\\*\" -ErrorAction SilentlyContinue | Where-Object {\n $_.DisplayName -and ($_.DisplayName -eq $displayName -or $_.DisplayName -like \"$displayName *\") -and\n ($publisher -eq \"\" -or $_.Publisher -like \"*$publisher*\")\n }\n if ($items) { $uninstall = $items | Select-Object -First 1; break }\n}\nif (-not $uninstall -or -not $uninstall.UninstallString) { Write-Host \"Uninstall entry not found\"; Exit 0 }\n$uninstallString = $uninstall.UninstallString\n$exePath = \"\"\nif ($uninstallString -match '^\"([^\"]+)\"(.*)') { $exePath = $matches[1] }\nelseif ($uninstallString -match '^(.+?\\.exe)(.*)$') { $exePath = $matches[1] }\nelse { Write-Host \"Error: Could not parse uninstall string: $uninstallString\"; Exit 1 }\n$installDir = if ($uninstall.InstallLocation -and (Test-Path -LiteralPath $uninstall.InstallLocation)) { $uninstall.InstallLocation.TrimEnd('\\') } else { (Split-Path -Parent $exePath).TrimEnd('\\') }\n$argumentList = @(\"/VERYSILENT\", \"/NORESTART\")\ntry {\n $processOptions = @{ FilePath = $exePath; ArgumentList = $argumentList; NoNewWindow = $true; PassThru = $true; Wait = $true }\n $process = Start-Process @processOptions\n $exitCode = $process.ExitCode\n Write-Host \"Uninstall exit code: $exitCode\"\n # Only sweep leftovers on a successful uninstall, and never a root/short path\n if ($exitCode -eq 0 -and $installDir) {\n $resolvedDir = $null\n try { $resolvedDir = (Resolve-Path -LiteralPath $installDir -ErrorAction Stop).Path } catch { $resolvedDir = $null }\n if ($resolvedDir -and ($resolvedDir -match '^[A-Za-z]:\\\\') -and ((($resolvedDir.TrimEnd('\\')) -split '\\\\').Count -ge 3) -and (Test-Path -LiteralPath $resolvedDir)) {\n Remove-Item -LiteralPath $resolvedDir -Recurse -Force -ErrorAction SilentlyContinue\n }\n }\n Exit $exitCode\n} catch { Write-Host \"Error running uninstaller: $_\"; Exit 1 }\n", - "e01b1635": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n#\n# This app ships as an Inno Setup installer.\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n\ntry {\n if (-not (Test-Path $exeFilePath)) {\n Write-Host \"Error: Installer file not found at: $exeFilePath\"\n Exit 1\n }\n\n $processOptions = @{\n FilePath = \"$exeFilePath\"\n ArgumentList = \"/VERYSILENT /SUPPRESSMSGBOXES /NORESTART\"\n PassThru = $true\n Wait = $true\n NoNewWindow = $true\n }\n\n $process = Start-Process @processOptions\n $exitCode = $process.ExitCode\n Write-Host \"Install exit code: $exitCode\"\n Exit $exitCode\n\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n" + "33a84921": "# DevToys installs per user, so its uninstall entry is in the installing user's\n# registry hive rather than SYSTEM's, and Inno Setup's uninstaller removes the\n# install directory recorded in the hive of whoever runs it -- run as SYSTEM\n# against a user's install it would miss that user's copy. So search every hive\n# and run the uninstaller as the user who owns the entry. A copy belonging to a\n# user who isn't signed in can't be removed and fails the uninstall.\n\n$displayNamePattern = '^DevToys\\s'\n$publisher = \"DevToys\"\n$taskName = \"fleet-uninstall-devtoys\"\n$appDir = \"AppData\\Local\\Programs\\DevToys Preview\" # in each user's profile\n$taskRunning = 267009 # SCHED_S_TASK_RUNNING\n$timeoutSeconds = 300\n$exitCode = 0\n\nfunction Get-AppEntries {\n $roots = [System.Collections.Generic.List[string]]::new()\n $roots.Add('HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall')\n $roots.Add('HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall')\n # Only SYSTEM's hive and user hives (S-1-5-21 local or AD, S-1-12-1 Entra ID).\n # LocalService and NetworkService can write their own hives, and an entry\n # there would run as SYSTEM.\n foreach ($hive in (Get-ChildItem 'Registry::HKEY_USERS' -ErrorAction SilentlyContinue)) {\n if ($hive.PSChildName -notmatch '^(S-1-5-18|S-1-5-21-[\\d-]+|S-1-12-1-[\\d-]+)$') { continue }\n $roots.Add(\"Registry::$($hive.Name)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\")\n $roots.Add(\"Registry::$($hive.Name)\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\")\n }\n\n $entries = @()\n foreach ($root in $roots) {\n foreach ($sub in (Get-ChildItem -Path $root -ErrorAction SilentlyContinue)) {\n $key = Get-ItemProperty $sub.PSPath -ErrorAction SilentlyContinue\n if (-not $key.DisplayName) { continue }\n # Some installers pad these values with nulls (Fork writes \"Fork\" + 15 of them).\n $name = ($key.DisplayName -replace \"`0\", \"\").Trim()\n if ($name -notmatch $displayNamePattern) { continue }\n if (($key.Publisher -replace \"`0\", \"\").Trim() -ne $publisher) { continue }\n\n # Only a real user's entry needs the uninstaller run for them; HKLM and\n # SYSTEM's hive are already in the right context.\n $sid = $null\n if ($sub.PSPath -match 'HKEY_USERS\\\\(S-1-5-21-[\\d-]+|S-1-12-1-[\\d-]+)\\\\') { $sid = $matches[1] }\n\n $entries += [PSCustomObject]@{\n DisplayName = $name\n KeyPath = $sub.PSPath\n Sid = $sid\n Command = if ($key.QuietUninstallString) { $key.QuietUninstallString } else { $key.UninstallString }\n }\n }\n }\n return $entries\n}\n\n# Registry hives of users who aren't signed in aren't loaded, so find their\n# copies by the app folder in their profiles instead.\nfunction Get-SignedOutInstalls {\n foreach ($profileKey in (Get-ChildItem 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList' -ErrorAction SilentlyContinue)) {\n $sid = $profileKey.PSChildName\n if ($sid -notmatch '^S-1-(5-21|12-1)-[\\d-]+$' -or (Test-Path \"Registry::HKEY_USERS\\$sid\")) { continue }\n $profilePath = (Get-ItemProperty $profileKey.PSPath -ErrorAction SilentlyContinue).ProfileImagePath\n if (-not $profilePath) { continue }\n if (-not (Test-Path -LiteralPath (Join-Path $profilePath \"$appDir\\DevToys.exe\"))) { continue }\n try {\n (New-Object System.Security.Principal.SecurityIdentifier($sid)).Translate([System.Security.Principal.NTAccount]).Value\n } catch {\n $sid\n }\n }\n}\n\nfunction Resolve-Uninstaller {\n param([string]$Command)\n\n $exePath = \"\"\n $arguments = \"\"\n if ($Command -match '^\\s*\"([^\"]+)\"\\s*(.*)$') {\n $exePath = $matches[1]\n $arguments = $matches[2].Trim()\n } elseif ($Command -match '(?i)^\\s*(.+?\\.exe)\\s*(.*)$') {\n $exePath = $matches[1]\n $arguments = $matches[2].Trim()\n }\n\n # A user's entry could point at a share that collects the computer account's\n # credentials, so only a drive-letter path is touched as SYSTEM. PowerShell\n # also reaches a share without a leading \\\\, as FileSystem::\\\\host\\share.\n if ($exePath -and $exePath -notmatch '^[A-Za-z]:[\\\\/]') { return $null }\n\n # A 32-bit installer run as SYSTEM is redirected into SysWOW64, but records the\n # unredirected system32 path that 64-bit PowerShell cannot resolve.\n if ($exePath -and -not (Test-Path -LiteralPath $exePath)) {\n $redirected = $exePath -replace '(?i)\\\\system32\\\\', '\\SysWOW64\\'\n if ($redirected -ne $exePath -and (Test-Path -LiteralPath $redirected)) {\n Write-Host \" Uninstaller is under SysWOW64, not the recorded $exePath\"\n $exePath = $redirected\n }\n }\n\n # Inno Setup: /VERYSILENT runs without any UI; the registered QuietUninstallString\n # uses /SILENT, which still shows a progress window nobody can see or dismiss.\n $arguments = ($arguments -replace '(?i)(^|\\s)/(VERY)?SILENT(?=$|\\s)', ' ').Trim()\n $arguments = \"$arguments /VERYSILENT /SUPPRESSMSGBOXES /NORESTART\".Trim()\n\n return [PSCustomObject]@{ ExePath = $exePath; Arguments = $arguments }\n}\n\nfunction Invoke-AsUser {\n param([string]$Sid, [string]$ExePath, [string]$Arguments)\n\n $account = (New-Object System.Security.Principal.SecurityIdentifier($Sid)).Translate(\n [System.Security.Principal.NTAccount]).Value\n Write-Host \" Running as ${account}: $ExePath $Arguments\"\n\n try {\n $action = New-ScheduledTaskAction -Execute $ExePath -Argument $Arguments\n $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries\n $principal = New-ScheduledTaskPrincipal -UserId $account\n $task = New-ScheduledTask -Action $action -Settings $settings -Principal $principal\n Register-ScheduledTask -TaskName $taskName -InputObject $task -Force -ErrorAction Stop | Out-Null\n\n $startDate = Get-Date\n $lastRun = (Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop).LastRunTime\n Start-ScheduledTask -TaskName $taskName -ErrorAction Stop\n\n # Wait for a result rather than for the \"Running\" state, which a fast task can\n # enter and leave between polls. A task that's still queued hasn't updated\n # LastRunTime yet.\n Start-Sleep -Seconds 2\n while ($true) {\n $info = Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop\n $state = (Get-ScheduledTask -TaskName $taskName -ErrorAction Stop).State\n if ($info.LastRunTime -ne $lastRun -and $state -ne \"Running\" -and $info.LastTaskResult -ne $taskRunning) {\n return $info.LastTaskResult\n }\n if ((New-TimeSpan -Start $startDate).TotalSeconds -gt $timeoutSeconds) {\n Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue\n Write-Host \" Timed out waiting for the task to finish.\"\n return 1460 # ERROR_TIMEOUT\n }\n Start-Sleep -Seconds 5\n }\n } finally {\n if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) {\n Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue\n }\n }\n}\n\n# A user can write to their own profile, including swapping a folder for a link\n# elsewhere, so their folder is removed as them rather than as SYSTEM. cmd\n# expands %VAR% even inside quotes, so a path containing % is never passed to it.\nfunction Remove-AppDir {\n param([string]$Path, [string]$Sid)\n\n if ($Sid -and $Path.Contains('%')) {\n Write-Host \" Could not remove $Path.\"\n return $false\n }\n if ($Sid) {\n try {\n $null = Invoke-AsUser -Sid $Sid -ExePath \"$env:SystemRoot\\System32\\cmd.exe\" -Arguments \"/d /c rd /s /q `\"$Path`\"\"\n } catch {\n Write-Host \" $_\"\n }\n } else {\n Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue\n }\n if (Test-Path -LiteralPath $Path) {\n Write-Host \" Could not remove $Path.\"\n return $false\n }\n return $true\n}\n\n# Shortcuts the uninstaller didn't get to. Match on where they point rather than on\n# a filename, which also catches the vendor subfolders some installers create. Read\n# as SYSTEM, a user's shortcut resolves its target through SYSTEM's profile, so the\n# working directory is checked too, and only the owning profile is searched. A\n# user's shortcuts are deleted as that user, like their folder.\nfunction Remove-Shortcuts {\n param([string]$Dir, [string]$ProfilePath, [string]$Sid)\n\n if ($ProfilePath) {\n $roots = @((Join-Path $ProfilePath 'AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs'), (Join-Path $ProfilePath 'Desktop'))\n } else {\n $roots = @('Programs', 'Desktop', 'CommonPrograms', 'CommonDesktopDirectory') | ForEach-Object { [Environment]::GetFolderPath($_) }\n }\n $found = @()\n $shell = New-Object -ComObject WScript.Shell\n foreach ($root in $roots) {\n if (-not $root -or -not (Test-Path -LiteralPath $root)) { continue }\n foreach ($lnk in (Get-ChildItem -LiteralPath $root -Filter '*.lnk' -Recurse -ErrorAction SilentlyContinue)) {\n try { $link = $shell.CreateShortcut($lnk.FullName) } catch { continue }\n foreach ($path in @($link.TargetPath, $link.WorkingDirectory)) {\n if ($path -and ($path -eq $Dir -or $path.StartsWith(\"$Dir\\\", [System.StringComparison]::OrdinalIgnoreCase))) {\n $found += $lnk.FullName\n break\n }\n }\n }\n }\n if (-not $found) { return }\n if ($Sid) {\n $quoted = ($found | Where-Object { -not $_.Contains('%') } | ForEach-Object { \"`\"$_`\"\" }) -join ' '\n if ($quoted) {\n try {\n $null = Invoke-AsUser -Sid $Sid -ExePath \"$env:SystemRoot\\System32\\cmd.exe\" -Arguments \"/d /c del /f /q $quoted\"\n } catch {\n Write-Host \" $_\"\n }\n }\n } else {\n $found | ForEach-Object { Remove-Item -LiteralPath $_ -Force -ErrorAction SilentlyContinue }\n }\n $found | Where-Object { Test-Path -LiteralPath $_ } | ForEach-Object { Write-Host \" Could not remove shortcut $_.\" }\n}\n\ntry {\n $entries = @(Get-AppEntries)\n\n foreach ($entry in $entries) {\n Write-Host \"Removing '$($entry.DisplayName)' ($($entry.KeyPath))\"\n $uninstaller = Resolve-Uninstaller $entry.Command\n if (-not $uninstaller) {\n Write-Host \" Skipping this copy: its uninstaller isn't on a local drive.\"\n if ($exitCode -eq 0) { $exitCode = 1 }\n continue\n }\n $hasUninstaller = $uninstaller.ExePath -and (Test-Path -LiteralPath $uninstaller.ExePath)\n\n # A user's uninstall string comes from a hive that user can write to, so only\n # touch the app's folder in that user's own profile.\n $installDir = \"\"\n if ($uninstaller.ExePath) { try { $installDir = [System.IO.Path]::GetFullPath((Split-Path $uninstaller.ExePath -Parent)) } catch {} }\n # Resolve-Uninstaller redirects only an uninstaller it can find, so without one\n # a 32-bit installer's SYSTEM-profile copy still points into system32.\n if (-not $entry.Sid -and $installDir -and -not (Test-Path -LiteralPath $installDir)) {\n $redirected = $installDir -replace '(?i)\\\\system32\\\\', '\\SysWOW64\\'\n if (Test-Path -LiteralPath $redirected) { $installDir = $redirected }\n }\n $isAppDir = $installDir -and (Split-Path $installDir -Leaf) -eq (Split-Path $appDir -Leaf)\n $profilePath = $null\n if ($entry.Sid) {\n $profilePath = (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\$($entry.Sid)\" -ErrorAction SilentlyContinue).ProfileImagePath\n $userAppDir = if ($profilePath) { Join-Path $profilePath $appDir } else { \"\" }\n if (-not $hasUninstaller) { $installDir = $userAppDir }\n $isAppDir = $userAppDir -and $installDir -eq $userAppDir\n }\n\n if ($isAppDir) {\n # Anything running out of this install directory blocks removal. Matching on the\n # directory rather than a process name keeps another install of the same app,\n # in another user's profile, running.\n Get-Process -ErrorAction SilentlyContinue |\n Where-Object { $_.Path -and $_.Path.StartsWith(\"$installDir\\\", [System.StringComparison]::OrdinalIgnoreCase) } |\n Stop-Process -Force -ErrorAction SilentlyContinue\n }\n\n if (-not $hasUninstaller) {\n Write-Host \" Uninstaller is missing; removing what's left of this copy.\"\n if ($installDir -and (Test-Path -LiteralPath $installDir) -and\n -not ($isAppDir -and (Remove-AppDir $installDir $entry.Sid))) {\n Write-Host \" Leaving this copy registered because $installDir is still there.\"\n if ($exitCode -eq 0) { $exitCode = 1 }\n continue\n }\n if ($isAppDir) { Remove-Shortcuts $installDir $profilePath $entry.Sid }\n Remove-Item -Path $entry.KeyPath -Recurse -Force -ErrorAction SilentlyContinue\n continue\n }\n\n # Caught here so one copy's failure doesn't skip the others.\n try {\n if ($entry.Sid) {\n $result = Invoke-AsUser -Sid $entry.Sid -ExePath $uninstaller.ExePath -Arguments $uninstaller.Arguments\n } else {\n Write-Host \" Uninstall command: $($uninstaller.ExePath) $($uninstaller.Arguments)\"\n $process = Start-Process -FilePath $uninstaller.ExePath -ArgumentList $uninstaller.Arguments `\n -NoNewWindow -PassThru -ErrorAction Stop\n $null = $process.Handle # keeps ExitCode readable after the process exits\n if ($process.WaitForExit($timeoutSeconds * 1000)) {\n $result = $process.ExitCode\n } else {\n Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue\n Write-Host \" Timed out waiting for the uninstaller to finish.\"\n $result = 1460 # ERROR_TIMEOUT\n }\n }\n } catch {\n Write-Host \" Could not run the uninstaller: $_\"\n $result = 1\n }\n Write-Host \" Uninstall exit code: $result\"\n if ($result -ne 0) {\n Write-Host \" Leaving this copy registered so the uninstall can be retried.\"\n if ($exitCode -eq 0) { $exitCode = $result }\n continue\n }\n\n # An uninstaller that relaunches itself from %TEMP% exits while removal is\n # still in flight. Either the directory or the registration going away means\n # it got there.\n for ($waited = 0; $waited -lt 60; $waited++) {\n if (-not (Test-Path -LiteralPath $installDir)) { break }\n if (-not (Get-ItemProperty $entry.KeyPath -ErrorAction SilentlyContinue)) {\n Start-Sleep -Seconds 3\n break\n }\n Start-Sleep -Seconds 1\n }\n\n if ($isAppDir -and (Test-Path -LiteralPath $installDir)) {\n Write-Host \" Uninstaller left $installDir behind; removing it.\"\n if (-not (Remove-AppDir $installDir $entry.Sid)) {\n if ($exitCode -eq 0) { $exitCode = 1 }\n continue\n }\n }\n if ($isAppDir) { Remove-Shortcuts $installDir $profilePath $entry.Sid }\n\n if (Get-ItemProperty $entry.KeyPath -ErrorAction SilentlyContinue) {\n Remove-Item -Path $entry.KeyPath -Recurse -Force -ErrorAction SilentlyContinue\n }\n }\n\n $remaining = @(Get-AppEntries)\n $signedOut = @(Get-SignedOutInstalls)\n if ($remaining.Count -gt 0) {\n Write-Host \"WARNING: $($remaining.Count) DevToys registration(s) still present:\"\n $remaining | ForEach-Object { Write-Host \" - $($_.DisplayName) [$($_.KeyPath)]\" }\n if ($exitCode -eq 0) { $exitCode = 1 }\n }\n if ($signedOut.Count -gt 0) {\n Write-Host \"DevToys is still installed for users who aren't signed in: $($signedOut -join ', '). Run the uninstall again while they're signed in.\"\n if ($exitCode -eq 0) { $exitCode = 1 }\n }\n if ($exitCode -eq 0) {\n if ($entries.Count) { Write-Host \"DevToys removed.\" } else { Write-Host \"DevToys is not installed.\" }\n }\n\n} catch {\n Write-Host \"Error running uninstaller: $_\"\n $exitCode = 1\n}\n\n# Exit turns a code above Int32.MaxValue, such as a task's HRESULT, into 0.\nif ($exitCode -gt [int]::MaxValue) { $exitCode = 1 }\nExit $exitCode\n", + "5d1dabad": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n#\n# DevToys ships as an Inno Setup installer whose install directory is\n# {userpf}\\DevToys Preview, so it installs per user and has no machine-wide\n# mode. Installing it from this script's SYSTEM context would put it in\n# SYSTEM's profile where nobody can launch it. Run the installer as the\n# signed-in user instead.\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n$taskName = \"fleet-install-devtoys\"\n$taskRunning = 267009 # SCHED_S_TASK_RUNNING\n$exitCode = 0\n$stageDir = $null\n\ntry {\n $owner = Get-CimInstance Win32_Process -Filter 'name = \"explorer.exe\"' -ErrorAction SilentlyContinue |\n Invoke-CimMethod -MethodName GetOwner -ErrorAction SilentlyContinue |\n Where-Object { $_.User } |\n Select-Object -First 1\n if (-not $owner) {\n Throw \"DevToys installs per user and no user is signed in to this host. Sign in and try again.\"\n }\n $userAccount = \"$($owner.Domain)\\$($owner.User)\"\n $sid = (New-Object System.Security.Principal.NTAccount($userAccount)).Translate(\n [System.Security.Principal.SecurityIdentifier]).Value\n Write-Host \"Installing DevToys for $userAccount.\"\n\n # Setup can't close a running DevToys from the scheduled task's logon session,\n # so it would wait on a \"files in use\" prompt until this script times out.\n # Stop what's running from the user's install first.\n $profilePath = (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\$sid\" -ErrorAction SilentlyContinue).ProfileImagePath\n if ($profilePath) {\n $appDir = Join-Path $profilePath \"AppData\\Local\\Programs\\DevToys Preview\"\n $isAppProcess = { $_.Path -and $_.Path.StartsWith(\"$appDir\\\", [System.StringComparison]::OrdinalIgnoreCase) }\n $running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object $isAppProcess)\n if ($running.Count) {\n Write-Host \"Stopping DevToys: $(($running | ForEach-Object { \"$($_.Name) ($($_.Id))\" }) -join ', ')\"\n # Windows reuses PIDs, so match the start time too.\n $stopped = @($running | ForEach-Object { \"$($_.Id)|$($_.StartTime.Ticks)\" })\n $running | Stop-Process -Force -ErrorAction SilentlyContinue\n for ($waited = 0; $waited -lt 30; $waited++) {\n Start-Sleep -Seconds 1\n $running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object $isAppProcess |\n Where-Object { $stopped -contains \"$($_.Id)|$($_.StartTime.Ticks)\" })\n if ($running.Count -eq 0) { break }\n }\n if ($running.Count) {\n Throw \"DevToys is still running ($(($running | ForEach-Object { \"$($_.Name) ($($_.Id))\" }) -join ', ')) and Setup can't replace it. Quit it and try again.\"\n }\n }\n }\n\n # Fleet's installer directory is not readable by that user, so stage a copy in\n # a new folder only SYSTEM and Administrators can write to.\n $security = New-Object System.Security.AccessControl.DirectorySecurity\n $security.SetAccessRuleProtection($true, $false)\n foreach ($grant in @(@(\"S-1-5-18\", \"FullControl\"), @(\"S-1-5-32-544\", \"FullControl\"), @($sid, \"ReadAndExecute\"))) {\n $security.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(\n (New-Object System.Security.Principal.SecurityIdentifier($grant[0])), $grant[1],\n \"ContainerInherit, ObjectInherit\", \"None\", \"Allow\")))\n }\n $stageDir = Join-Path $env:ProgramData (\"fleet-devtoys-\" + [guid]::NewGuid().ToString(\"N\"))\n [void][System.IO.Directory]::CreateDirectory($stageDir, $security)\n $stagedInstaller = Join-Path $stageDir (Split-Path $exeFilePath -Leaf)\n Copy-Item -LiteralPath $exeFilePath -Destination $stagedInstaller -Force -ErrorAction Stop\n\n # Inno Setup: /VERYSILENT runs without any UI (the NSIS /S switch does nothing).\n $action = New-ScheduledTaskAction -Execute $stagedInstaller -Argument \"/VERYSILENT /SUPPRESSMSGBOXES /NORESTART\"\n $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries\n $principal = New-ScheduledTaskPrincipal -UserId $userAccount\n $task = New-ScheduledTask -Action $action -Settings $settings -Principal $principal\n Register-ScheduledTask -TaskName $taskName -InputObject $task -Force -ErrorAction Stop | Out-Null\n\n $startDate = Get-Date\n $lastRun = (Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop).LastRunTime\n Start-ScheduledTask -TaskName $taskName -ErrorAction Stop\n\n # Wait for a result rather than for the \"Running\" state, which a fast task can\n # enter and leave between polls. A task that's still queued hasn't updated\n # LastRunTime yet.\n Start-Sleep -Seconds 2\n while ($true) {\n $info = Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction Stop\n $state = (Get-ScheduledTask -TaskName $taskName -ErrorAction Stop).State\n if ($info.LastRunTime -ne $lastRun -and $state -ne \"Running\" -and $info.LastTaskResult -ne $taskRunning) {\n $exitCode = $info.LastTaskResult\n break\n }\n if ((New-TimeSpan -Start $startDate).TotalSeconds -gt 900) {\n Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue\n Throw \"Timed out waiting for the install task to finish.\"\n }\n Start-Sleep -Seconds 5\n }\n Write-Host \"Install exit code: $exitCode\"\n\n} catch {\n Write-Host \"Error: $_\"\n $exitCode = 1\n} finally {\n if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) {\n Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue\n }\n if ($stageDir -and (Test-Path -LiteralPath $stageDir)) {\n Remove-Item -LiteralPath $stageDir -Recurse -Force -ErrorAction SilentlyContinue\n }\n}\n\n# Exit turns a code above Int32.MaxValue, such as a task's HRESULT, into 0.\nif ($exitCode -gt [int]::MaxValue) { $exitCode = 1 }\nExit $exitCode\n" } } diff --git a/ee/maintained-apps/outputs/docker/windows.json b/ee/maintained-apps/outputs/docker/windows.json index a268bf7fbd2..78f84e95b85 100644 --- a/ee/maintained-apps/outputs/docker/windows.json +++ b/ee/maintained-apps/outputs/docker/windows.json @@ -8,7 +8,7 @@ "open": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM processes WHERE LOWER(name) = 'docker desktop.exe');" }, "installer_url": "https://desktop.docker.com/win/main/amd64/247138/Docker%20Desktop%20Installer.exe", - "install_script_ref": "b06042dd", + "install_script_ref": "ab8f97aa", "uninstall_script_ref": "0b74af50", "sha256": "98b24fd6f56313899953ca4d2ed05645d69963b598143b75c6585fa4f7f639b2", "default_categories": [ @@ -18,6 +18,6 @@ ], "refs": { "0b74af50": "# Define acceptable/expected exit codes\n$ExpectedExitCodes = @(0, 19)\n\n# Docker Desktop can be installed per-user (HKCU, %LOCALAPPDATA%) or\n# all-users (HKLM, C:\\Program Files). Check HKCU first, then HKLM.\n$registryPaths = @(\n 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop',\n 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop'\n)\n\n# Initialize exit code\n$exitCode = 0\n\ntry {\n $key = $null\n foreach ($path in $registryPaths) {\n $candidate = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue\n if ($candidate) {\n Write-Host \"Found Docker Desktop registry at: $path\"\n $key = $candidate\n break\n }\n }\n if (-not $key) {\n Throw \"Docker Desktop registry entry not found in HKCU or HKLM.\"\n }\n\n # Get the uninstall command. Some uninstallers do not include 'QuietUninstallString'\n $uninstallCommand = if ($key.QuietUninstallString) {\n $key.QuietUninstallString\n } else {\n $key.UninstallString\n }\n\n # The expected uninstall command value is \"\\Docker Desktop Installer.exe\" \"uninstall\"\n $splitArgs = $uninstallCommand.Split('\"')\n if ($splitArgs.Length -ne 5) {\n Throw \"Unexpected uninstall command. Please update the uninstall script.`nUninstall command: $uninstallCommand\"\n }\n $uninstallCommand = $splitArgs[1]\n $uninstallArgs = $splitArgs[3]\n\n Write-Host \"Uninstall command: $uninstallCommand\"\n Write-Host \"Uninstall args: $uninstallArgs\"\n\n $processOptions = @{\n FilePath = $uninstallCommand\n PassThru = $true\n Wait = $true\n }\n if ($uninstallArgs -ne '') {\n $processOptions.ArgumentList = \"$uninstallArgs --quiet\"\n } else {\n $processOptions.ArgumentList = \"--quiet\"\n }\n\n # Start uninstall process\n $process = Start-Process @processOptions\n $exitCode = $process.ExitCode\n Write-Host \"Uninstall exit code: $exitCode\"\n\n} catch {\n Write-Host \"Error: $_\"\n $exitCode = 1\n}\n\n# Treat acceptable exit codes as success\nif ($ExpectedExitCodes -contains $exitCode) {\n Exit 0\n} else {\n Exit $exitCode\n}\n", - "b06042dd": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n\ntry {\n # Docker Desktop 4.72+ added a per-user vs all-user install choice for\n # Windows. All-user silent installs hang on Windows Server runners\n # (Docker Desktop is not officially supported on Windows Server). Install\n # per-user with --user instead: no admin needed, target is\n # %LOCALAPPDATA%\\Programs\\DockerDesktop, and uninstall info is written to\n # HKCU. --accept-license suppresses the subscription agreement prompt.\n Start-Process -FilePath \"$exeFilePath\" -ArgumentList \"install\",\"--user\",\"--accept-license\",\"--quiet\" | Out-Null\n\n # The installer process can keep running for several minutes after the\n # app is registered with Windows. Poll the HKCU uninstall key (osquery's\n # programs table reads both HKLM and HKU) to detect when the core install\n # has completed, rather than blocking on Start-Process -Wait.\n $registryKey = \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop\"\n $deadline = (Get-Date).AddMinutes(4)\n while ((Get-Date) -lt $deadline) {\n if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) {\n Write-Host \"Docker Desktop registered in HKCU.\"\n Exit 0\n }\n Start-Sleep -Seconds 10\n }\n\n Write-Host \"Docker Desktop did not register within timeout.\"\n Exit 1\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n" + "ab8f97aa": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n#\n# Docker Desktop refuses \"install --user\" when it is run by the SYSTEM account,\n# because that would install it into the SYSTEM profile. Run the all-users\n# install instead: it needs administrator rights, puts the app in\n# C:\\Program Files\\Docker\\Docker and registers it in HKLM.\n#\n# Users who need Windows containers or Hyper-V VM management must also be in\n# the local docker-users group; the all-users install does not add them.\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n$registryKey = \"HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop\"\n\ntry {\n # --accept-license suppresses the subscription agreement prompt.\n $process = Start-Process -FilePath \"$exeFilePath\" `\n -ArgumentList \"install\",\"--accept-license\",\"--quiet\" -PassThru\n # Touch the handle so ExitCode is still readable after the process exits.\n $null = $process.Handle\n\n # The installer process can keep running for a while after the app is\n # registered with Windows, so stop waiting as soon as the registration is\n # there rather than blocking on the process.\n $deadline = (Get-Date).AddMinutes(8)\n while ((Get-Date) -lt $deadline) {\n if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) {\n Write-Host \"Docker Desktop registered in HKLM.\"\n Exit 0\n }\n if ($process.HasExited) {\n # Registration can land a moment after the installer exits.\n Start-Sleep -Seconds 10\n if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) {\n Write-Host \"Docker Desktop registered in HKLM.\"\n Exit 0\n }\n Write-Host \"Install exit code: $($process.ExitCode)\"\n Write-Host \"The installer exited without registering Docker Desktop. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n if ($process.ExitCode -eq 0) { Exit 1 }\n Exit $process.ExitCode\n }\n Start-Sleep -Seconds 10\n }\n\n Write-Host \"Docker Desktop did not register within 8 minutes. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n Exit 1\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n" } } diff --git a/ee/maintained-apps/outputs/webex/windows.json b/ee/maintained-apps/outputs/webex/windows.json index 01737ce28dd..291c2a370ae 100644 --- a/ee/maintained-apps/outputs/webex/windows.json +++ b/ee/maintained-apps/outputs/webex/windows.json @@ -8,7 +8,7 @@ "open": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM processes WHERE LOWER(name) = 'webex.exe');" }, "installer_url": "https://binaries.webex.com/WebexDesktop-Win-64-Gold/20261103185347/Webex.msi", - "install_script_ref": "22e48c46", + "install_script_ref": "80d34df0", "uninstall_script_ref": "c641c6f7", "sha256": "377c529583527ca22f11980bb3a9d73328470a9b5ba6c747c9e826b2512885a5", "default_categories": [ @@ -18,7 +18,7 @@ } ], "refs": { - "22e48c46": "$logFile = \"${env:TEMP}/fleet-install-software.log\"\n\n# MSI exit codes that indicate success. 3010 = ERROR_SUCCESS_REBOOT_REQUIRED,\n# 1641 = ERROR_SUCCESS_REBOOT_INITIATED. Treat these as success rather than failure.\n$successCodes = @(0, 3010, 1641)\n\ntry {\n\n$installProcess = Start-Process msiexec.exe `\n -ArgumentList \"/quiet /norestart /lv `\"${logFile}`\" /i `\"${env:INSTALLER_PATH}`\"\" `\n -PassThru -Verb RunAs -Wait\n\nGet-Content $logFile -Tail 500\n\nif ($successCodes -contains $installProcess.ExitCode) {\n Exit 0\n}\n\nExit $installProcess.ExitCode\n\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n", + "80d34df0": "# Learn more about install scripts:\n# http://fleetdm.com/learn-more-about/install-scripts\n#\n# Webex's MSI is a dual-purpose package that defaults to a per-user install\n# (ALLUSERS=2, MSIINSTALLPERUSER=1), so under Fleet's SYSTEM context it lands in\n# the SYSTEM account's profile, where no one can open it. Force the per-machine\n# install into Program Files, which is also what enables the Outlook\n# integration. First remove a copy an earlier install left in the SYSTEM\n# profile, so it isn't left behind unreachable.\n\n$logFile = \"${env:TEMP}/fleet-install-software.log\"\n$upgradeCode = '{B9DCA8E9-B3A9-419A-9D6F-9BC3557EE72C}'\n\n# 3010 = reboot required, 1641 = reboot initiated\n$successCodes = @(0, 3010, 1641)\n\ntry {\n\n$installer = New-Object -ComObject \"WindowsInstaller.Installer\"\n\nforeach ($productCode in @($installer.RelatedProducts($upgradeCode))) {\n # 0 = installed for this account only; 1 = installed machine-wide\n if ($installer.ProductInfo($productCode, \"AssignmentType\") -ne \"0\") { continue }\n\n Write-Host \"Removing the copy of Webex in the SYSTEM profile ($productCode)\"\n $removeProcess = Start-Process msiexec.exe `\n -ArgumentList \"/quiet /norestart /x $productCode\" `\n -PassThru -Wait\n if ($successCodes -notcontains $removeProcess.ExitCode) {\n Write-Host \"Removal exited $($removeProcess.ExitCode)\"\n Exit $removeProcess.ExitCode\n }\n}\n\n$installProcess = Start-Process msiexec.exe `\n -ArgumentList \"/quiet /norestart /lv `\"${logFile}`\" ALLUSERS=1 MSIINSTALLPERUSER=`\"`\" /i `\"${env:INSTALLER_PATH}`\"\" `\n -PassThru -Wait\n\nGet-Content $logFile -Tail 500\n\nif ($successCodes -contains $installProcess.ExitCode) {\n Exit 0\n}\n\nExit $installProcess.ExitCode\n\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n", "c641c6f7": "# Fleet uninstalls app by finding all related product codes for the specified upgrade code\n$ErrorActionPreference = 'Stop'\n$inst = New-Object -ComObject \"WindowsInstaller.Installer\"\n$timeoutSeconds = 300 # 5 minute timeout per product\n\n# MSI exit codes that indicate success. 3010 = ERROR_SUCCESS_REBOOT_REQUIRED,\n# 1641 = ERROR_SUCCESS_REBOOT_INITIATED. Treat these as success rather than failure.\n$successCodes = @(0, 3010, 1641)\n\nforeach ($product_code in $inst.RelatedProducts('{B9DCA8E9-B3A9-419A-9D6F-9BC3557EE72C}')) {\n $process = Start-Process msiexec -ArgumentList @(\"/quiet\", \"/x\", $product_code, \"/norestart\") -PassThru\n\n # Wait for process with timeout\n $completed = $process.WaitForExit($timeoutSeconds * 1000)\n\n if (-not $completed) {\n Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue\n Exit 1603 # ERROR_UNINSTALL_FAILURE\n }\n\n # If the uninstall failed, bail\n if ($successCodes -notcontains $process.ExitCode) {\n Write-Output \"Uninstall for $($product_code) exited $($process.ExitCode)\"\n Exit $process.ExitCode\n }\n}\n\n# All uninstalls succeeded; exit success\nExit 0\n" } } From 470d74c746752f3a0993248134857a172f1635b7 Mon Sep 17 00:00:00 2001 From: Allen Houchins Date: Tue, 24 Nov 2026 01:19:23 -0600 Subject: [PATCH 2/2] Don't take an existing Docker Desktop registration as this install's success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses CodeRabbit review on this PR. On a host that already had an all-users install, the HKLM key was there before the installer started, so the first poll returned 0 immediately and Fleet recorded a success for the previous install — the reinstall case. Wait for this installer to exit, check its code, and only then confirm the registration. --- .../inputs/winget/scripts/docker_install.ps1 | 47 +++++++++++-------- .../outputs/docker/windows.json | 4 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 b/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 index 4774394a5da..85a0b06ba0d 100644 --- a/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 +++ b/ee/maintained-apps/inputs/winget/scripts/docker_install.ps1 @@ -11,39 +11,46 @@ $exeFilePath = "${env:INSTALLER_PATH}" $registryKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Docker Desktop" +# 3010 = reboot required, 1641 = reboot initiated +$expectedExitCodes = @(0, 1641, 3010) try { + $before = Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue + if ($before) { + Write-Host "Docker Desktop $($before.DisplayVersion) is already installed; installing over it." + } + # --accept-license suppresses the subscription agreement prompt. $process = Start-Process -FilePath "$exeFilePath" ` -ArgumentList "install","--accept-license","--quiet" -PassThru # Touch the handle so ExitCode is still readable after the process exits. $null = $process.Handle - # The installer process can keep running for a while after the app is - # registered with Windows, so stop waiting as soon as the registration is - # there rather than blocking on the process. - $deadline = (Get-Date).AddMinutes(8) + # Wait for this install to finish. A registration that is already there + # belongs to the previous install and says nothing about this one. + if (-not $process.WaitForExit(8 * 60 * 1000)) { + Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue + Write-Host "The installer did not finish within 8 minutes. See C:\ProgramData\DockerDesktop\install-log-admin.txt." + Exit 1 + } + + $exitCode = $process.ExitCode + Write-Host "Install exit code: $exitCode" + if ($expectedExitCodes -notcontains $exitCode) { Exit $exitCode } + + # Child processes finish the registration, so it can land a little after the + # installer exits. Wait for the entry osquery's programs table reads. + $deadline = (Get-Date).AddMinutes(2) while ((Get-Date) -lt $deadline) { - if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) { - Write-Host "Docker Desktop registered in HKLM." + $after = Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue + if ($after) { + Write-Host "Docker Desktop $($after.DisplayVersion) registered in HKLM." Exit 0 } - if ($process.HasExited) { - # Registration can land a moment after the installer exits. - Start-Sleep -Seconds 10 - if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) { - Write-Host "Docker Desktop registered in HKLM." - Exit 0 - } - Write-Host "Install exit code: $($process.ExitCode)" - Write-Host "The installer exited without registering Docker Desktop. See C:\ProgramData\DockerDesktop\install-log-admin.txt." - if ($process.ExitCode -eq 0) { Exit 1 } - Exit $process.ExitCode - } - Start-Sleep -Seconds 10 + Start-Sleep -Seconds 5 } - Write-Host "Docker Desktop did not register within 8 minutes. See C:\ProgramData\DockerDesktop\install-log-admin.txt." + Write-Host "The installer exited $exitCode but Docker Desktop is not registered. See C:\ProgramData\DockerDesktop\install-log-admin.txt." Exit 1 } catch { Write-Host "Error: $_" diff --git a/ee/maintained-apps/outputs/docker/windows.json b/ee/maintained-apps/outputs/docker/windows.json index 78f84e95b85..974903d4b8d 100644 --- a/ee/maintained-apps/outputs/docker/windows.json +++ b/ee/maintained-apps/outputs/docker/windows.json @@ -8,7 +8,7 @@ "open": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM processes WHERE LOWER(name) = 'docker desktop.exe');" }, "installer_url": "https://desktop.docker.com/win/main/amd64/247138/Docker%20Desktop%20Installer.exe", - "install_script_ref": "ab8f97aa", + "install_script_ref": "158b8eaf", "uninstall_script_ref": "0b74af50", "sha256": "98b24fd6f56313899953ca4d2ed05645d69963b598143b75c6585fa4f7f639b2", "default_categories": [ @@ -18,6 +18,6 @@ ], "refs": { "0b74af50": "# Define acceptable/expected exit codes\n$ExpectedExitCodes = @(0, 19)\n\n# Docker Desktop can be installed per-user (HKCU, %LOCALAPPDATA%) or\n# all-users (HKLM, C:\\Program Files). Check HKCU first, then HKLM.\n$registryPaths = @(\n 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop',\n 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop'\n)\n\n# Initialize exit code\n$exitCode = 0\n\ntry {\n $key = $null\n foreach ($path in $registryPaths) {\n $candidate = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue\n if ($candidate) {\n Write-Host \"Found Docker Desktop registry at: $path\"\n $key = $candidate\n break\n }\n }\n if (-not $key) {\n Throw \"Docker Desktop registry entry not found in HKCU or HKLM.\"\n }\n\n # Get the uninstall command. Some uninstallers do not include 'QuietUninstallString'\n $uninstallCommand = if ($key.QuietUninstallString) {\n $key.QuietUninstallString\n } else {\n $key.UninstallString\n }\n\n # The expected uninstall command value is \"\\Docker Desktop Installer.exe\" \"uninstall\"\n $splitArgs = $uninstallCommand.Split('\"')\n if ($splitArgs.Length -ne 5) {\n Throw \"Unexpected uninstall command. Please update the uninstall script.`nUninstall command: $uninstallCommand\"\n }\n $uninstallCommand = $splitArgs[1]\n $uninstallArgs = $splitArgs[3]\n\n Write-Host \"Uninstall command: $uninstallCommand\"\n Write-Host \"Uninstall args: $uninstallArgs\"\n\n $processOptions = @{\n FilePath = $uninstallCommand\n PassThru = $true\n Wait = $true\n }\n if ($uninstallArgs -ne '') {\n $processOptions.ArgumentList = \"$uninstallArgs --quiet\"\n } else {\n $processOptions.ArgumentList = \"--quiet\"\n }\n\n # Start uninstall process\n $process = Start-Process @processOptions\n $exitCode = $process.ExitCode\n Write-Host \"Uninstall exit code: $exitCode\"\n\n} catch {\n Write-Host \"Error: $_\"\n $exitCode = 1\n}\n\n# Treat acceptable exit codes as success\nif ($ExpectedExitCodes -contains $exitCode) {\n Exit 0\n} else {\n Exit $exitCode\n}\n", - "ab8f97aa": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n#\n# Docker Desktop refuses \"install --user\" when it is run by the SYSTEM account,\n# because that would install it into the SYSTEM profile. Run the all-users\n# install instead: it needs administrator rights, puts the app in\n# C:\\Program Files\\Docker\\Docker and registers it in HKLM.\n#\n# Users who need Windows containers or Hyper-V VM management must also be in\n# the local docker-users group; the all-users install does not add them.\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n$registryKey = \"HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop\"\n\ntry {\n # --accept-license suppresses the subscription agreement prompt.\n $process = Start-Process -FilePath \"$exeFilePath\" `\n -ArgumentList \"install\",\"--accept-license\",\"--quiet\" -PassThru\n # Touch the handle so ExitCode is still readable after the process exits.\n $null = $process.Handle\n\n # The installer process can keep running for a while after the app is\n # registered with Windows, so stop waiting as soon as the registration is\n # there rather than blocking on the process.\n $deadline = (Get-Date).AddMinutes(8)\n while ((Get-Date) -lt $deadline) {\n if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) {\n Write-Host \"Docker Desktop registered in HKLM.\"\n Exit 0\n }\n if ($process.HasExited) {\n # Registration can land a moment after the installer exits.\n Start-Sleep -Seconds 10\n if (Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue) {\n Write-Host \"Docker Desktop registered in HKLM.\"\n Exit 0\n }\n Write-Host \"Install exit code: $($process.ExitCode)\"\n Write-Host \"The installer exited without registering Docker Desktop. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n if ($process.ExitCode -eq 0) { Exit 1 }\n Exit $process.ExitCode\n }\n Start-Sleep -Seconds 10\n }\n\n Write-Host \"Docker Desktop did not register within 8 minutes. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n Exit 1\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n" + "158b8eaf": "# Learn more about .exe install scripts:\n# http://fleetdm.com/learn-more-about/exe-install-scripts\n#\n# Docker Desktop refuses \"install --user\" when it is run by the SYSTEM account,\n# because that would install it into the SYSTEM profile. Run the all-users\n# install instead: it needs administrator rights, puts the app in\n# C:\\Program Files\\Docker\\Docker and registers it in HKLM.\n#\n# Users who need Windows containers or Hyper-V VM management must also be in\n# the local docker-users group; the all-users install does not add them.\n\n$exeFilePath = \"${env:INSTALLER_PATH}\"\n$registryKey = \"HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop\"\n# 3010 = reboot required, 1641 = reboot initiated\n$expectedExitCodes = @(0, 1641, 3010)\n\ntry {\n $before = Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue\n if ($before) {\n Write-Host \"Docker Desktop $($before.DisplayVersion) is already installed; installing over it.\"\n }\n\n # --accept-license suppresses the subscription agreement prompt.\n $process = Start-Process -FilePath \"$exeFilePath\" `\n -ArgumentList \"install\",\"--accept-license\",\"--quiet\" -PassThru\n # Touch the handle so ExitCode is still readable after the process exits.\n $null = $process.Handle\n\n # Wait for this install to finish. A registration that is already there\n # belongs to the previous install and says nothing about this one.\n if (-not $process.WaitForExit(8 * 60 * 1000)) {\n Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue\n Write-Host \"The installer did not finish within 8 minutes. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n Exit 1\n }\n\n $exitCode = $process.ExitCode\n Write-Host \"Install exit code: $exitCode\"\n if ($expectedExitCodes -notcontains $exitCode) { Exit $exitCode }\n\n # Child processes finish the registration, so it can land a little after the\n # installer exits. Wait for the entry osquery's programs table reads.\n $deadline = (Get-Date).AddMinutes(2)\n while ((Get-Date) -lt $deadline) {\n $after = Get-ItemProperty -Path $registryKey -ErrorAction SilentlyContinue\n if ($after) {\n Write-Host \"Docker Desktop $($after.DisplayVersion) registered in HKLM.\"\n Exit 0\n }\n Start-Sleep -Seconds 5\n }\n\n Write-Host \"The installer exited $exitCode but Docker Desktop is not registered. See C:\\ProgramData\\DockerDesktop\\install-log-admin.txt.\"\n Exit 1\n} catch {\n Write-Host \"Error: $_\"\n Exit 1\n}\n" } }