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

72 行
3.1KB

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

Powered by TurnKey Linux.