2026-05-06 19:43:30 -04:00
# DragonMoonlight Pre-Installation Check Script
# Runs elevated before files are copied during installation
param ( )
$ErrorActionPreference = " Stop "
2026-05-06 19:47:52 -04:00
# Validate Windows.Forms availability before using it
$hasWinForms = $false
try {
Add-Type -AssemblyName System . Windows . Forms -ErrorAction Stop
$hasWinForms = $true
} catch {
# Constrained environment — fall back to console output only
}
2026-05-06 19:43:30 -04:00
function Write-Info { Write-Host $args -ForegroundColor Cyan }
function Write-Success { Write-Host $args -ForegroundColor Green }
function Write-Warning { Write-Host $args -ForegroundColor Yellow }
function Write-Error { Write-Host $args -ForegroundColor Red }
2026-05-06 19:47:52 -04:00
function Show-Dialog($msg , $title , $icon ) {
if ( $hasWinForms ) {
[ System.Windows.Forms.MessageBox ] :: Show ( $msg , $title ,
[ System.Windows.Forms.MessageBoxButtons ] :: OK , $icon ) | Out-Null
} else {
Write-Host " [ $title ] $msg " -ForegroundColor Red
}
}
2026-05-06 19:43:30 -04:00
try {
Write-Info " === DragonMoonlight Pre-Installation Checks === "
# Check if running elevated
$isElevated = ( [ Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity ] :: GetCurrent ( ) ) . IsInRole ( [ Security.Principal.WindowsBuiltInRole ] " Administrator " )
if ( -not $isElevated ) {
Write-Error " This script must run elevated (as Administrator). Installation cannot proceed. "
2026-05-06 19:47:52 -04:00
Show-Dialog (
2026-05-06 19:43:30 -04:00
" DragonMoonlight installation failed. `r `n This installer requires Administrator privileges. " ,
" Installation Error " ,
2026-05-06 19:47:52 -04:00
[ System.Windows.Forms.MessageBoxIcon ] :: Error
2026-05-06 19:43:30 -04:00
)
exit 1
}
Write-Success " ✓ Running with elevated privileges "
# Check Windows version
$osVersion = [ Environment ] :: OSVersion . Version
$buildNumber = [ int ] ( Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' 'CurrentBuildNumber' ) . CurrentBuildNumber
Write-Info " Windows version: $( $osVersion . Major ) . $( $osVersion . Minor ) Build $buildNumber "
# Wintun requires Windows 10 2004 (Build 19041) or later
if ( $buildNumber -lt 19041 ) {
Write-Error " This system does not meet the minimum requirements. "
Write-Error " DragonMoonlight requires Windows 10 (Build 19041/2004) or later. "
Write-Error " Current build: $buildNumber "
2026-05-06 19:47:52 -04:00
Show-Dialog (
2026-05-06 19:43:30 -04:00
" DragonMoonlight requires Windows 10 (Build 2004) or later. `r `n `r `n Your system is running Build $buildNumber , which does not support the required Windows Filtering Platform features for Wintun. `r `n `r `n Please update Windows and try again. " ,
" Unsupported Windows Version " ,
2026-05-06 19:47:52 -04:00
[ System.Windows.Forms.MessageBoxIcon ] :: Error
2026-05-06 19:43:30 -04:00
)
exit 1
}
Write-Success " ✓ Windows version check passed (Build $buildNumber >= 19041) "
# Warn about driver signature enforcement
Write-Info " Checking driver signature enforcement status... "
try {
$signingLevel = ( Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\SecureBoot\State' 'UEFISecureBootEnabled' -ErrorAction SilentlyContinue ) . UEFISecureBootEnabled
if ( $signingLevel -eq 1 ) {
Write-Warning " ⚠ Secure Boot is enabled. Ensure that Wintun driver signing certificate is trusted. "
} else {
Write-Success " ✓ Secure Boot is disabled or not detected "
}
} catch {
Write-Info " Could not determine Secure Boot status (this is normal on non-UEFI systems) "
}
# Log pre-install success to event log
Write-Info " Logging pre-installation check to event log... "
try {
if ( -not ( [ System.Diagnostics.EventLog ] :: SourceExists ( " DragonMoonlight " ) ) ) {
New-EventLog -LogName Application -Source " DragonMoonlight " -ErrorAction SilentlyContinue
}
Write-EventLog -LogName Application -Source " DragonMoonlight " -EventId 1000 `
-Message " DragonMoonlight pre-install check passed. Build: $buildNumber " -EntryType Information
Write-Success " ✓ Event log entry created "
} catch {
Write-Warning " Could not write to event log (non-critical): $_ "
}
Write-Success " === Pre-installation checks completed successfully === "
exit 0
}
catch {
Write-Error " Pre-installation check failed: $_ "
2026-05-06 19:47:52 -04:00
Show-Dialog (
2026-05-06 19:43:30 -04:00
" Pre-installation check failed: `r `n `r `n $_ " ,
" Installation Error " ,
2026-05-06 19:47:52 -04:00
[ System.Windows.Forms.MessageBoxIcon ] :: Error
2026-05-06 19:43:30 -04:00
)
exit 1
}