<# .SYNOPSIS This script downloads CMTrace and assigns it as the default application for .log files via Default App Associations. .DESCRIPTION XML import affects new profiles; the policy enforces the mapping at each sign-in. Pure registry association (ProgID + .log) may be ignored by UserChoice and is not recommended. .NOTES Version: 0.1 Creation Date: 20.10.2025 Author: Akos Bakos Company: SmartCon GmbH Contact: akos.bakos@smartcon.ch Copyright (c) 2025 SmartCon GmbH HISTORY: Date By Comments ---------- --- ---------------------------------------------------------- 20.10.2025 Akos Bakos Script created 03.11.2025 Akos Bakos New file associations for .log and .lo_ files #> # Runs during OOBE as SYSTEM $Global:Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Copy_Assign_CMTrace.log" Start-Transcript -Path (Join-Path "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD\" $Global:Transcript) -ErrorAction Ignore | Out-Null # Ensure TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 # Vars $url = 'https://patchmypc.com/cmtrace' $destDir = 'C:\Program Files\CMTrace' $exePath = Join-Path $destDir 'CMTrace.exe' # Create destination New-Item -Path $destDir -ItemType Directory -Force | Out-Null # Download directly to final path Write-Host "Downloading CMTrace to $exePath..." Invoke-WebRequest -Uri $url -OutFile $exePath -ErrorAction Stop | Out-Null # Basic validation (PE header "MZ") $header = [byte[]](Get-Content -Path $exePath -Encoding Byte -TotalCount 2) if ($header.Length -ne 2 -or $header[0] -ne 0x4D -or $header[1] -ne 0x5A) { Remove-Item $exePath -Force -ErrorAction SilentlyContinue throw "Downloaded file doesn't look like a valid executable." } # Associate .log and .lo_ files to CMtrace and make it the default app to open them New-Item -Path 'HKLM:\Software\Classes\.lo_' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Classes\.log' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Classes\.log.File' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Classes\.Log.File\shell' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Classes\Log.File\shell\Open' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Classes\Log.File\shell\Open\Command' -Type Directory -Force -ErrorAction SilentlyContinue New-Item -Path 'HKLM:\Software\Microsoft\Trace32' -Type Directory -Force -ErrorAction SilentlyContinue # Create the properties to make CMtrace the default log viewer New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\.lo_' -Name '(default)' -Value "Log.File" -PropertyType String -Force -ea SilentlyContinue; New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\.log' -Name '(default)' -Value "Log.File" -PropertyType String -Force -ea SilentlyContinue; New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\Log.File\shell\open\command' -Name '(default)' -Value "`"C:\Program Files\CMTrace\CMTrace.exe`" `"%1`"" -PropertyType String -Force -ea SilentlyContinue; # Create an ActiveSetup that will remove the initial question in CMtrace if it should be the default reader New-Item -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -Type Directory New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -Name "Version" -Value 1 -PropertyType String -Force New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -Name "StubPath" -Value "reg.exe add HKCU\Software\Microsoft\Trace32 /v ""Register File Types"" /d 0 /f" -PropertyType ExpandString -Force Stop-Transcript | Out-Null