#Requires -RunAsAdministrator
<#
.SYNOPSIS
    Adds the Kittle file server to the Local Intranet zone so PDF preview
    works on network shares (blocked by Oct 2025 security update).

.DESCRIPTION
    Windows security updates from October 14, 2025 onward disable preview
    for files in the "Internet Zone". UNC shares may be classified as Internet
    Zone if not explicitly added to Local Intranet or Trusted Sites.

    This script adds \\SERVER and \\10.0.0.5 to the Local Intranet zone
    (zone 1) via HKLM registry so it applies to all users on the machine.

    Run on WORKSTATIONS ONLY — not needed on the server.

.NOTES
    Ref: https://support.microsoft.com/en-us/topic/56d55920-6187-4aae-a4f6-102454ef61fb
#>

$ErrorActionPreference = 'Stop'

# Zone 1 = Local Intranet
$zone = 1
$basePath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap'

# Add server by hostname
$hostKey = Join-Path $basePath 'Domains\SERVER'
if (-not (Test-Path $hostKey)) {
    New-Item -Path $hostKey -Force | Out-Null
}
Set-ItemProperty -Path $hostKey -Name 'file' -Value $zone -Type DWord
Write-Host "Added \\SERVER to Local Intranet zone" -ForegroundColor Green

# Add server by IP
$ipKey = Join-Path $basePath 'Domains\10.0.0.5'
if (-not (Test-Path $ipKey)) {
    New-Item -Path $ipKey -Force | Out-Null
}
Set-ItemProperty -Path $ipKey -Name 'file' -Value $zone -Type DWord
Write-Host "Added \\10.0.0.5 to Local Intranet zone" -ForegroundColor Green

# Also add to EscDomains in case IE ESC is somehow enabled
$escBase = Join-Path $basePath 'EscDomains'
if (Test-Path $escBase) {
    $escHostKey = Join-Path $escBase 'SERVER'
    if (-not (Test-Path $escHostKey)) {
        New-Item -Path $escHostKey -Force | Out-Null
    }
    Set-ItemProperty -Path $escHostKey -Name 'file' -Value $zone -Type DWord

    $escIpKey = Join-Path $escBase '10.0.0.5'
    if (-not (Test-Path $escIpKey)) {
        New-Item -Path $escIpKey -Force | Out-Null
    }
    Set-ItemProperty -Path $escIpKey -Name 'file' -Value $zone -Type DWord
    Write-Host "Added to EscDomains as well" -ForegroundColor Green
}

Write-Host "`nDone. Restart File Explorer or log off/on for changes to take effect." -ForegroundColor Cyan
Write-Host "Verify: Internet Options > Security > Local Intranet > Sites > Advanced" -ForegroundColor Cyan
