- 03-system-registry.ps1: Set-Reg now has 3-tier retry: direct write, ACL manipulation, fallback to scheduled task running as SYSTEM (which has unrestricted registry access - handles TrustedInstaller-owned keys) - 02-software.ps1: add Acrobat DC path (Acrobat.exe) before legacy AcroRd32.exe paths - winget installs Acrobat DC not Reader DC - 06-scheduled-tasks.ps1: same Adobe path fix in PDF-DefaultApp script - tests/Test-Deployment.ps1: Adobe check covers both Acrobat DC and Reader DC install paths Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
124 lines
4.5 KiB
PowerShell
124 lines
4.5 KiB
PowerShell
param(
|
|
[object]$Config,
|
|
[string]$LogFile
|
|
)
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
function Write-Log {
|
|
param([string]$Message, [string]$Level = "INFO")
|
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
|
}
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Check winget availability
|
|
# -----------------------------------------------------------------------
|
|
Write-Log "Checking winget availability" -Level INFO
|
|
|
|
$winget = Get-Command winget -ErrorAction SilentlyContinue
|
|
if (-not $winget) {
|
|
# Try to find winget in known locations
|
|
$wingetPaths = @(
|
|
"$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe"
|
|
"$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller*\winget.exe"
|
|
)
|
|
foreach ($p in $wingetPaths) {
|
|
$found = Get-Item $p -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
if ($found) { $winget = $found.FullName; break }
|
|
}
|
|
}
|
|
|
|
if (-not $winget) {
|
|
Write-Log "winget not found - software installation skipped" -Level ERROR
|
|
exit 1
|
|
}
|
|
|
|
Write-Log "winget found: $($winget.Source -or $winget)" -Level OK
|
|
|
|
# Accept agreements upfront
|
|
& winget source update --accept-source-agreements 2>&1 | Out-Null
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Install packages from config
|
|
# -----------------------------------------------------------------------
|
|
if (-not $Config -or -not $Config.software -or -not $Config.software.install) {
|
|
Write-Log "No software list in config - skipping installs" -Level WARN
|
|
} else {
|
|
foreach ($pkg in $Config.software.install) {
|
|
Write-Log "Installing $($pkg.name) ($($pkg.wingetId))" -Level INFO
|
|
$result = & winget install --id $pkg.wingetId `
|
|
--silent `
|
|
--accept-package-agreements `
|
|
--accept-source-agreements `
|
|
--disable-interactivity `
|
|
2>&1
|
|
|
|
$exitCode = $LASTEXITCODE
|
|
if ($exitCode -eq 0) {
|
|
Write-Log " Installed OK: $($pkg.name)" -Level OK
|
|
} elseif ($exitCode -eq -1978335189) {
|
|
# 0x8A150011 = already installed
|
|
Write-Log " Already installed: $($pkg.name)" -Level OK
|
|
} else {
|
|
Write-Log " Failed: $($pkg.name) (exit $exitCode)" -Level ERROR
|
|
Write-Log " Output: $($result -join ' ')" -Level ERROR
|
|
}
|
|
}
|
|
}
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Set Adobe Reader as default PDF app
|
|
# -----------------------------------------------------------------------
|
|
$forcePdf = $true
|
|
if ($Config -and $Config.pdfDefault) {
|
|
$forcePdf = [bool]$Config.pdfDefault.forceAdobeReader
|
|
}
|
|
|
|
if ($forcePdf) {
|
|
Write-Log "Setting Adobe Reader as default PDF app" -Level INFO
|
|
|
|
# Find Adobe PDF viewer executable (Acrobat DC or Reader DC)
|
|
$acroPaths = @(
|
|
"$env:ProgramFiles\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
|
|
"${env:ProgramFiles(x86)}\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
|
|
"${env:ProgramFiles(x86)}\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
|
|
"$env:ProgramFiles\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
|
|
"${env:ProgramFiles(x86)}\Adobe\Reader\Reader\AcroRd32.exe"
|
|
)
|
|
$acroExe = $acroPaths | Where-Object { Test-Path $_ } | Select-Object -First 1
|
|
|
|
if (-not $acroExe) {
|
|
Write-Log " Adobe PDF viewer not found - PDF default not set" -Level WARN
|
|
} else {
|
|
Write-Log " Found: $acroExe" -Level INFO
|
|
|
|
# Set file type association via HKCR (system-wide, requires admin)
|
|
$progId = "AcroExch.Document.DC"
|
|
$openCmd = "`"$acroExe`" `"%1`""
|
|
|
|
# HKCR\.pdf -> progId
|
|
if (-not (Test-Path "HKCR:\.pdf")) {
|
|
New-Item -Path "HKCR:\.pdf" -Force | Out-Null
|
|
}
|
|
Set-ItemProperty -Path "HKCR:\.pdf" -Name "(Default)" -Value $progId
|
|
|
|
# HKCR\AcroExch.Document.DC\shell\open\command
|
|
$cmdPath = "HKCR:\$progId\shell\open\command"
|
|
if (-not (Test-Path $cmdPath)) {
|
|
New-Item -Path $cmdPath -Force | Out-Null
|
|
}
|
|
Set-ItemProperty -Path $cmdPath -Name "(Default)" -Value $openCmd
|
|
|
|
# Also set in HKCU for current user (UserChoice)
|
|
$ucPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice"
|
|
if (-not (Test-Path $ucPath)) {
|
|
New-Item -Path $ucPath -Force | Out-Null
|
|
}
|
|
Set-ItemProperty -Path $ucPath -Name "ProgId" -Value $progId
|
|
|
|
Write-Log " PDF default set to AcroRd32" -Level OK
|
|
}
|
|
}
|
|
|
|
Write-Log "Step 2 complete" -Level OK
|