[CmdletBinding()] param( [string]$ProjectRoot ) if (-not $ProjectRoot) { $ProjectRoot = Split-Path -Parent $PSScriptRoot } # NOTE (see docs/DECISIONS.md): on this host, `regsvr32 /s /u component.wsc` reports # exit code 0 but leaves the ProgID/CLSID registry entries in place - verified experimentally, # not a theoretical concern. regsvr32 /u is still attempted first (best effort, harmless if it # no-ops), then registry state is checked and, if the entries survived, they are removed # explicitly - scoped to exactly this project's ProgID/CLSID pairs so an unrelated component # can never be touched even if it happened to reuse a ProgID string. $components = @( @{ Path = (Join-Path $ProjectRoot 'test-app\Controllers\SelfTestController.wsc'); ProgId = 'WscMvc.SelfTestController'; ClassId = '{D2634944-4646-4C55-956E-4C05E7E10904}' }, @{ Path = (Join-Path $ProjectRoot 'Controllers\HomeController.wsc'); ProgId = 'WscMvc.HomeController'; ClassId = '{87488446-60BE-4068-8368-0B709BB68F3F}' }, @{ Path = (Join-Path $ProjectRoot 'Framework\Application.wsc'); ProgId = 'WscMvc.Application'; ClassId = '{851C7763-1638-42FE-A166-BF3DD3A96A88}' }, @{ Path = (Join-Path $ProjectRoot 'Framework\RequestContext.wsc'); ProgId = 'WscMvc.RequestContext'; ClassId = '{1C36FA55-34DF-4974-94B9-D657389362B2}' } ) function Remove-ProjectComponent { param([string]$ProgId, [string]$ClassId) $progIdKey = "HKLM:\SOFTWARE\Classes\$ProgId" $clsidKey = "HKLM:\SOFTWARE\Classes\CLSID\$ClassId" $registeredClassId = $null if (Test-Path "$progIdKey\CLSID") { $registeredClassId = (Get-ItemProperty "$progIdKey\CLSID" -ErrorAction SilentlyContinue).'(default)' } if (-not (Test-Path $progIdKey) -and -not (Test-Path $clsidKey)) { Write-Output " Already absent: $ProgId / $ClassId" return } if ($registeredClassId -and $registeredClassId -ne $ClassId) { throw "Refusing to remove '$ProgId': registered CLSID ($registeredClassId) does not match this project's expected CLSID ($ClassId). This ProgID may belong to a different component." } if (Test-Path $progIdKey) { Remove-Item -Path $progIdKey -Recurse -Force Write-Output " Removed $progIdKey" } if (Test-Path $clsidKey) { Remove-Item -Path $clsidKey -Recurse -Force Write-Output " Removed $clsidKey" } } foreach ($component in $components) { $path = $component.Path if (-not (Test-Path $path)) { Write-Warning "Component not found, skipping: $path" continue } Write-Output "Unregistering $path" $proc = Start-Process -FilePath 'regsvr32.exe' -ArgumentList "/s /u `"$path`"" -PassThru -Wait -WindowStyle Hidden if ($proc.ExitCode -ne 0) { Write-Warning "regsvr32 /u reported exit $($proc.ExitCode) for $path; verifying registry state directly" } Remove-ProjectComponent -ProgId $component.ProgId -ClassId $component.ClassId } Write-Output "All WSC-MVC components unregistered."