1+ # This script will scan the registry for all keys associated with install,
2+ # create a log file, and optionally delete them (not recommended - uninstall via Inno Setup unins000.exe)
3+
4+ $ProgID = " SolverWrapper"
5+ $GuidPrefix = " 71A00FE4-A1D4-47C3-BC7A-"
6+ $LogPath = " .\COM_Registry_Log.txt"
7+ $Delete = $false
8+
9+ $ProgIDPattern = " $ProgID .*"
10+
11+ $log = New-Object System.Collections.Generic.List[string ]
12+ function Log ($msg ) {
13+ $timestamped = " $ ( Get-Date - Format ' yyyy-MM-dd HH:mm:ss' ) $msg "
14+ $log.Add ($timestamped )
15+ Add-Content - Path $LogPath - Value $timestamped
16+ Write-Host $timestamped
17+ }
18+
19+ function MatchKeys ($basePath , $pattern ) {
20+ Log " Scanning: $basePath with pattern: $pattern "
21+ try {
22+ $items = Get-ChildItem - Path " Registry::$basePath " - ErrorAction SilentlyContinue
23+ $matches = $items | Where-Object {
24+ $_.PSChildName -match " ^$pattern " -or $_.PSChildName -match " ^\{$pattern "
25+ } | ForEach-Object { $_.Name }
26+ Log " Matched $ ( $matches.Count ) keys"
27+ return $matches
28+ } catch {
29+ Log " Failed to scan: $basePath - $_ "
30+ return @ ()
31+ }
32+ }
33+
34+ function DeleteKey ($keyPath ) {
35+ try {
36+ Remove-Item - Path " Registry::$keyPath " - Recurse - Force - ErrorAction Stop
37+ Log " Deleted: $keyPath "
38+ } catch {
39+ Log " Failed to delete: $keyPath - $_ "
40+ }
41+ }
42+
43+ # Registry hives to scan
44+ $hives = @ (
45+ " HKCR" ,
46+ " HKCR\WOW6432Node" ,
47+ " HKCU\Software\Classes" ,
48+ " HKCU\Software\Classes\Wow6432Node" ,
49+ " HKCU\Software\Wow6432Node" ,
50+ " HKLM\Software\Classes" ,
51+ " HKLM\Software\Classes\WOW6432Node" ,
52+ " HKLM\Software\WOW6432Node\Classes"
53+ )
54+
55+ # "Software\Classes\TypeLib"
56+
57+ # Targets to match
58+ $targets = @ (
59+ @ { Path = " " ; Pattern = $ProgIDPattern },
60+ @ { Path = " CLSID" ; Pattern = " $GuidPrefix *" },
61+ @ { Path = " Interface" ; Pattern = " $GuidPrefix *" },
62+ @ { Path = " TypeLib" ; Pattern = " $GuidPrefix *" }
63+ )
64+
65+ foreach ($hive in $hives ) {
66+ foreach ($target in $targets ) {
67+ $base = if ($target.Path -eq " " ) { $hive } else { " $hive \$ ( $target.Path ) " }
68+ $matches = MatchKeys $base $target.Pattern
69+ foreach ($match in $matches ) {
70+ Log " Found: $match "
71+ if ($Delete ) { DeleteKey $match }
72+ }
73+ }
74+ }
75+
76+ # Detect Office version from Excel and Access
77+ function Get-OfficeVersion ($app ) {
78+ $key = " HKCU:\Software\Microsoft\Office"
79+ $versions = Get-ChildItem - Path $key - ErrorAction SilentlyContinue |
80+ Where-Object { $_.PSChildName -match ' ^\d+\.\d+$' } |
81+ Sort-Object - Property PSChildName - Descending
82+
83+ foreach ($version in $versions ) {
84+ $testPath = " $key \$ ( $version.PSChildName ) \$app \Security\Trusted Locations\$ProgID "
85+ if (Test-Path - Path $testPath ) {
86+ return $version.PSChildName
87+ }
88+ }
89+ return $null
90+ }
91+
92+ # Delete Trusted Location key
93+ function FindTrustedLocation ($app ) {
94+ $version = Get-OfficeVersion $app
95+ if ($version ) {
96+ $keyPath = " HKCU:\Software\Microsoft\Office\$version \$app \Security\Trusted Locations\$ProgID "
97+ if (Test-Path - Path $keyPath ) {
98+ Log " Found Trusted Location: $keyPath "
99+ if ($Delete ) {
100+ try {
101+ Remove-Item - Path $keyPath - Recurse - Force - ErrorAction Stop
102+ Log " Deleted Trusted Location: $keyPath "
103+ } catch {
104+ Log " Failed to delete $keyPath - $_ "
105+ }
106+ }
107+ } else {
108+ Log " No Trusted Location found for $app {$version }: $keyPath "
109+ }
110+
111+ } else {
112+ Log " No Trusted Location found for $app "
113+ }
114+ }
115+
116+ # Run cleanup
117+ FindTrustedLocation " Excel"
118+ FindTrustedLocation " Access"
119+
120+
121+ # Save log to file
122+ $log | Out-File - FilePath $LogPath - Encoding UTF8
123+ Log " Log saved to: $LogPath "
0 commit comments