Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

69 lignes
2.6KB

  1. [CmdletBinding()]
  2. param(
  3. [string]$ProjectRoot
  4. )
  5. if (-not $ProjectRoot) {
  6. $ProjectRoot = Split-Path -Parent $PSScriptRoot
  7. }
  8. # NOTE (see docs/DECISIONS.md): on this host, `regsvr32 /s /u component.wsc` reports
  9. # exit code 0 but leaves the ProgID/CLSID registry entries in place - verified experimentally,
  10. # not a theoretical concern. regsvr32 /u is still attempted first (best effort, harmless if it
  11. # no-ops), then registry state is checked and, if the entries survived, they are removed
  12. # explicitly - scoped to exactly this project's ProgID/CLSID pairs so an unrelated component
  13. # can never be touched even if it happened to reuse a ProgID string.
  14. $components = @(
  15. @{ Path = (Join-Path $ProjectRoot 'Controllers\HomeController.wsc'); ProgId = 'WscMvc.HomeController'; ClassId = '{87488446-60BE-4068-8368-0B709BB68F3F}' },
  16. @{ Path = (Join-Path $ProjectRoot 'Framework\Application.wsc'); ProgId = 'WscMvc.Application'; ClassId = '{851C7763-1638-42FE-A166-BF3DD3A96A88}' }
  17. )
  18. function Remove-ProjectComponent {
  19. param([string]$ProgId, [string]$ClassId)
  20. $progIdKey = "HKLM:\SOFTWARE\Classes\$ProgId"
  21. $clsidKey = "HKLM:\SOFTWARE\Classes\CLSID\$ClassId"
  22. $registeredClassId = $null
  23. if (Test-Path "$progIdKey\CLSID") {
  24. $registeredClassId = (Get-ItemProperty "$progIdKey\CLSID" -ErrorAction SilentlyContinue).'(default)'
  25. }
  26. if (-not (Test-Path $progIdKey) -and -not (Test-Path $clsidKey)) {
  27. Write-Output " Already absent: $ProgId / $ClassId"
  28. return
  29. }
  30. if ($registeredClassId -and $registeredClassId -ne $ClassId) {
  31. 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."
  32. }
  33. if (Test-Path $progIdKey) {
  34. Remove-Item -Path $progIdKey -Recurse -Force
  35. Write-Output " Removed $progIdKey"
  36. }
  37. if (Test-Path $clsidKey) {
  38. Remove-Item -Path $clsidKey -Recurse -Force
  39. Write-Output " Removed $clsidKey"
  40. }
  41. }
  42. foreach ($component in $components) {
  43. $path = $component.Path
  44. if (-not (Test-Path $path)) {
  45. Write-Warning "Component not found, skipping: $path"
  46. continue
  47. }
  48. Write-Output "Unregistering $path"
  49. $proc = Start-Process -FilePath 'regsvr32.exe' -ArgumentList "/s /u `"$path`"" -PassThru -Wait -WindowStyle Hidden
  50. if ($proc.ExitCode -ne 0) {
  51. Write-Warning "regsvr32 /u reported exit $($proc.ExitCode) for $path; verifying registry state directly"
  52. }
  53. Remove-ProjectComponent -ProgId $component.ProgId -ClassId $component.ClassId
  54. }
  55. Write-Output "All WSC-MVC components unregistered."

Powered by TurnKey Linux.