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.

70 lignes
2.8KB

  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. @{ Path = (Join-Path $ProjectRoot 'Framework\RequestContext.wsc'); ProgId = 'WscMvc.RequestContext'; ClassId = '{1C36FA55-34DF-4974-94B9-D657389362B2}' }
  18. )
  19. function Remove-ProjectComponent {
  20. param([string]$ProgId, [string]$ClassId)
  21. $progIdKey = "HKLM:\SOFTWARE\Classes\$ProgId"
  22. $clsidKey = "HKLM:\SOFTWARE\Classes\CLSID\$ClassId"
  23. $registeredClassId = $null
  24. if (Test-Path "$progIdKey\CLSID") {
  25. $registeredClassId = (Get-ItemProperty "$progIdKey\CLSID" -ErrorAction SilentlyContinue).'(default)'
  26. }
  27. if (-not (Test-Path $progIdKey) -and -not (Test-Path $clsidKey)) {
  28. Write-Output " Already absent: $ProgId / $ClassId"
  29. return
  30. }
  31. if ($registeredClassId -and $registeredClassId -ne $ClassId) {
  32. 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."
  33. }
  34. if (Test-Path $progIdKey) {
  35. Remove-Item -Path $progIdKey -Recurse -Force
  36. Write-Output " Removed $progIdKey"
  37. }
  38. if (Test-Path $clsidKey) {
  39. Remove-Item -Path $clsidKey -Recurse -Force
  40. Write-Output " Removed $clsidKey"
  41. }
  42. }
  43. foreach ($component in $components) {
  44. $path = $component.Path
  45. if (-not (Test-Path $path)) {
  46. Write-Warning "Component not found, skipping: $path"
  47. continue
  48. }
  49. Write-Output "Unregistering $path"
  50. $proc = Start-Process -FilePath 'regsvr32.exe' -ArgumentList "/s /u `"$path`"" -PassThru -Wait -WindowStyle Hidden
  51. if ($proc.ExitCode -ne 0) {
  52. Write-Warning "regsvr32 /u reported exit $($proc.ExitCode) for $path; verifying registry state directly"
  53. }
  54. Remove-ProjectComponent -ProgId $component.ProgId -ClassId $component.ClassId
  55. }
  56. Write-Output "All WSC-MVC components unregistered."

Powered by TurnKey Linux.