您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

71 行
2.9KB

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

Powered by TurnKey Linux.