This commit is contained in:
2025-09-07 08:56:06 -04:00

View File

@@ -137,10 +137,21 @@ function Install-ADTDeployment
$CurrentPDFLocal = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice'
$CurrentPDF = (Get-ItemProperty $CurrentPDFLocal -ErrorAction SilentlyContinue).ProgId
if ($CurrentPDF) {"ProgID: $p"}
else { "No association set" }
if ($CurrentPDF) {
Write-ADTLogEntry -Message ("Detected current PDF ProgID: {0}" -f $CurrentPDF) -Severity 1
}
else {
Write-ADTLogEntry -Message 'No current PDF association set' -Severity 2
}
Show-ADTInstallationPrompt -Message 'The current default PDF appliction is '$p'' -ButtonRightText 'Yes' -ButtonLeftText 'No'
# Show current default (friendly name if known) in interactive mode
try {
$currentFriendly = if ($CurrentPDF -and $PDFMap.ContainsKey($CurrentPDF)) { $PDFMap[$CurrentPDF] } else { $CurrentPDF }
if ($adtSession.DeployMode -eq 'Interactive') {
$msgFriendly = if ([string]::IsNullOrWhiteSpace($currentFriendly)) { 'Unknown' } else { $currentFriendly }
Show-ADTInstallationPrompt -Message ("Current default PDF application: {0}" -f $msgFriendly) -ButtonRightText 'OK'
}
} catch { Write-ADTLogEntry -Message ("Failed to show current default prompt: {0}" -f $_) -Severity 2 }
@@ -154,7 +165,7 @@ function Install-ADTDeployment
function Get-InstalledPDFProgIDs {
$installed = @()
foreach ($progId in $friendlyMap.Keys) { if (Is-ProgIDPresent $progId) { $installed += $progId } }
foreach ($progId in $PDFMap.Keys) { if (Is-ProgIDPresent $progId) { $installed += $progId } }
return $installed
}
@@ -168,12 +179,100 @@ function Install-ADTDeployment
} catch { return "Error" }
}
function Select-PDFProgId {
param(
[string[]]$Candidates,
[string]$Current
)
# If not interactive, prefer current; otherwise present a simple selection UI.
if ($adtSession.DeployMode -ne 'Interactive') { return $Current }
try {
Add-Type -AssemblyName System.Windows.Forms | Out-Null
Add-Type -AssemblyName System.Drawing | Out-Null
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Select Default PDF Handler'
$form.StartPosition = 'CenterScreen'
$form.Width = 520
$form.Height = 180
$form.Topmost = $true
$label = New-Object System.Windows.Forms.Label
$label.AutoSize = $true
$label.Text = 'Choose the application to handle .pdf files:'
$label.Location = New-Object System.Drawing.Point(12, 12)
$form.Controls.Add($label)
$combo = New-Object System.Windows.Forms.ComboBox
$combo.DropDownStyle = 'DropDownList'
$combo.Width = 480
$combo.Location = New-Object System.Drawing.Point(12, 40)
# Build display list of "Friendly (ProgID)"
$items = @()
foreach ($pid in $Candidates) {
$friendly = if ($PDFMap.ContainsKey($pid)) { $PDFMap[$pid] } else { $pid }
$items += ("{0} ({1})" -f $friendly, $pid)
}
$combo.Items.AddRange($items)
if ($Current -and $Candidates -contains $Current) {
$friendlyCur = if ($PDFMap.ContainsKey($Current)) { $PDFMap[$Current] } else { $Current }
$displayCur = ("{0} ({1})" -f $friendlyCur, $Current)
$combo.SelectedItem = $displayCur
} elseif ($combo.Items.Count -gt 0) {
$combo.SelectedIndex = 0
}
$form.Controls.Add($combo)
$ok = New-Object System.Windows.Forms.Button
$ok.Text = 'OK'
$ok.Width = 80
$ok.Location = New-Object System.Drawing.Point(332, 80)
$ok.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $ok
$form.Controls.Add($ok)
$cancel = New-Object System.Windows.Forms.Button
$cancel.Text = 'Cancel'
$cancel.Width = 80
$cancel.Location = New-Object System.Drawing.Point(412, 80)
$cancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancel
$form.Controls.Add($cancel)
$result = $form.ShowDialog()
if ($result -ne [System.Windows.Forms.DialogResult]::OK) { return $Current }
$selection = [string]$combo.SelectedItem
if (-not $selection) { return $Current }
# Extract ProgID from "Name (ProgID)"
$m = [regex]::Match($selection, '\(([^)]+)\)$')
if ($m.Success) { return $m.Groups[1].Value } else { return $Current }
} catch {
Write-ADTLogEntry -Message ("Selection UI failed: {0}" -f $_) -Severity 2
return $Current
}
}
##================================================
## MARK: Install
##================================================
$adtSession.InstallPhase = $adtSession.DeploymentType
Start-ADTProcessAsUser -FilePath "C:\ProgramData\SetUserFTA\SetUserFTA.exe" -ArgumentList '/S' -SuccessExitCodes 0, 500
# Determine desired ProgID and set association via SetUserFTA
$installedProgIds = Get-InstalledPDFProgIDs
$currentProgId = Get-CurrentPDFHandler
$targetProgId = Select-PDFProgId -Candidates $installedProgIds -Current $currentProgId
if ($targetProgId -and $targetProgId -ne 'Unknown' -and $targetProgId -ne 'Error') {
$args = ".pdf $targetProgId"
Write-ADTLogEntry -Message ("Setting .pdf handler to {0}" -f $targetProgId) -Severity 1
Start-ADTProcessAsUser -FilePath "C:\ProgramData\SetUserFTA\SetUserFTA.exe" -ArgumentList $args -SuccessExitCodes 0, 500
} else {
Write-ADTLogEntry -Message 'Skipping SetUserFTA: no valid target ProgID determined' -Severity 2
}
##================================================
## MARK: Post-Install