<# Clear-PCDMISRecent.ps1 Fixes the PC-DMIS startup crash: System.NullReferenceException at Adapter.Service.Recent.Models.RecentExecutedItem.LoadRealNode() at Adapter.Service.Recent.Models.RecentExecutedFiles.LoadAllWhenReady() Cause: the Homepage "Recent Executed Files" list contains absolute routine paths (S:\..., C:\geaofi\LocalProgramCopies\...). When a path does not resolve in the running user's context (drive not visible, cache not yet rebuilt, file gone), PC-DMIS dereferences a null while async-loading the list and crashes on launch. A list carried over from another bay (e.g. a settings restore) is the common trigger. Fix: delete the Recent (and Favorites) Homepage state for every user profile and every PC-DMIS version. PC-DMIS rebuilds an empty list on next start. Run as ADMINISTRATOR (to reach all user profiles). Output: C:\Logs\CMM\pcdmis-clearrecent--.log Params: -RecentOnly only clear the Recent list, keep Favorites -User only this user's profile (default: all profiles) #> param( [switch]$RecentOnly, [string]$User ) $ErrorActionPreference = 'Continue' $ts = Get-Date -Format 'yyyyMMdd-HHmmss' $dir = 'C:\Logs\CMM' New-Item -ItemType Directory -Path $dir -Force -ErrorAction SilentlyContinue | Out-Null $log = Join-Path $dir "pcdmis-clearrecent-$env:COMPUTERNAME-$ts.log" function Log($m){ Write-Host $m; $m | Out-File -FilePath $log -Append } Log "==== Clear PC-DMIS Recent/Favorites on $env:COMPUTERNAME at $(Get-Date) ====" # which user profiles $userDirs = @() if ($User) { if (Test-Path "C:\Users\$User") { $userDirs += "C:\Users\$User" } else { Log "User profile C:\Users\$User not found" } } else { $userDirs = (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName } $targets = @('Homepage\Recent\RecentExecutedFiles.xml') if (-not $RecentOnly) { $targets += 'Homepage\Favorites\Favorites.xml' } $deleted = 0; $scanned = 0 foreach ($u in $userDirs) { foreach ($vendor in 'Hexagon','WAI') { $base = Join-Path $u "AppData\Local\$vendor\PC-DMIS" if (-not (Test-Path $base)) { continue } foreach ($vdir in (Get-ChildItem $base -Directory -ErrorAction SilentlyContinue)) { $scanned++ foreach ($rel in $targets) { $f = Join-Path $vdir.FullName $rel if (Test-Path $f) { try { Remove-Item $f -Force -ErrorAction Stop; $deleted++ Log " DELETED $f" } catch { Log " FAILED $f : $($_.Exception.Message)" } } } } } } Log "" Log "Scanned $scanned PC-DMIS version folder(s) across $($userDirs.Count) profile(s); deleted $deleted file(s)." Log "PC-DMIS will rebuild an empty recent list on next launch." Write-Host "" if ($deleted -gt 0) { Write-Host "Cleared $deleted stale Homepage file(s). Relaunch PC-DMIS - the crash should be gone." -ForegroundColor Green } else { Write-Host "Nothing to clear (no RecentExecutedFiles.xml found). If it still crashes, the cause is elsewhere - grab the event log." -ForegroundColor Yellow } Log "Log: $log"