diff --git a/scripts/02-software.ps1 b/scripts/02-software.ps1 index 9e6eded..ab65ac1 100644 --- a/scripts/02-software.ps1 +++ b/scripts/02-software.ps1 @@ -78,8 +78,10 @@ if ($Config -and $Config.pdfDefault) { if ($forcePdf) { Write-Log "Setting Adobe Reader as default PDF app" -Level INFO - # Find AcroRd32.exe + # 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" @@ -87,7 +89,7 @@ if ($forcePdf) { $acroExe = $acroPaths | Where-Object { Test-Path $_ } | Select-Object -First 1 if (-not $acroExe) { - Write-Log " AcroRd32.exe not found - PDF default not set" -Level WARN + Write-Log " Adobe PDF viewer not found - PDF default not set" -Level WARN } else { Write-Log " Found: $acroExe" -Level INFO diff --git a/scripts/03-system-registry.ps1 b/scripts/03-system-registry.ps1 index a3e4f2a..83171f1 100644 --- a/scripts/03-system-registry.ps1 +++ b/scripts/03-system-registry.ps1 @@ -68,7 +68,7 @@ function Set-Reg { Write-Log " SET $Path\$Name = $Value" -Level OK } catch { - # Retry after granting write access + # Retry 1: grant write access via ACL manipulation try { Grant-RegWriteAccess -Path $Path if (-not (Test-Path $Path)) { @@ -76,6 +76,49 @@ function Set-Reg { } Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type $Type -Force -ErrorAction Stop Write-Log " SET $Path\$Name = $Value (after ACL fix)" -Level OK + return + } + catch { } + + # Retry 2: write via scheduled task running as SYSTEM + # SYSTEM has full registry access regardless of key ACL + try { + $regType = switch ($Type) { + "DWord" { "REG_DWORD" } + "String" { "REG_SZ" } + "ExpandString"{ "REG_EXPAND_SZ" } + "MultiString" { "REG_MULTI_SZ" } + "QWord" { "REG_QWORD" } + default { "REG_DWORD" } + } + # Convert registry PS path to reg.exe path + $regPath = $Path -replace '^HKLM:\\', 'HKLM\' ` + -replace '^HKCU:\\', 'HKCU\' ` + -replace '^HKCR:\\', 'HKCR\' + $tempScript = "$env:TEMP\set-reg-system-$([System.IO.Path]::GetRandomFileName()).ps1" + "reg add `"$regPath`" /v `"$Name`" /t $regType /d $Value /f" | + Set-Content -Path $tempScript -Encoding UTF8 + + $taskName = "TempRegFix-$([System.IO.Path]::GetRandomFileName())" + $action = New-ScheduledTaskAction -Execute "cmd.exe" ` + -Argument "/c reg add `"$regPath`" /v `"$Name`" /t $regType /d $Value /f" + $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest + $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Seconds 30) + $task = New-ScheduledTask -Action $action -Principal $principal -Settings $settings + + Register-ScheduledTask -TaskName $taskName -InputObject $task -Force | Out-Null + Start-ScheduledTask -TaskName $taskName + Start-Sleep -Seconds 2 + Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue + Remove-Item $tempScript -Force -ErrorAction SilentlyContinue + + # Verify it was written + $written = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name + if ($null -ne $written) { + Write-Log " SET $Path\$Name = $Value (via SYSTEM task)" -Level OK + } else { + Write-Log " FAILED $Path\$Name - SYSTEM task ran but value not found" -Level ERROR + } } catch { Write-Log " FAILED $Path\$Name - $_" -Level ERROR diff --git a/scripts/06-scheduled-tasks.ps1 b/scripts/06-scheduled-tasks.ps1 index 31b6745..d57182b 100644 --- a/scripts/06-scheduled-tasks.ps1 +++ b/scripts/06-scheduled-tasks.ps1 @@ -86,6 +86,8 @@ $pdfScript = "$ScriptDir\PDF-DefaultApp.ps1" @' # Restore .pdf -> Adobe Reader association $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" diff --git a/tests/Test-Deployment.ps1 b/tests/Test-Deployment.ps1 index 4189f02..7045d74 100644 --- a/tests/Test-Deployment.ps1 +++ b/tests/Test-Deployment.ps1 @@ -104,7 +104,9 @@ Test-Check "7-Zip installed" { (Test-Path "${env:ProgramFiles(x86)}\7-Zip\7z.exe") } -Test-Check "Adobe Acrobat Reader installed" { +Test-Check "Adobe Acrobat installed" { + (Test-Path "$env:ProgramFiles\Adobe\Acrobat DC\Acrobat\Acrobat.exe") -or + (Test-Path "${env:ProgramFiles(x86)}\Adobe\Acrobat DC\Acrobat\Acrobat.exe") -or (Test-Path "${env:ProgramFiles(x86)}\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe") -or (Test-Path "$env:ProgramFiles\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe") }