@@ -17,13 +17,11 @@ param(
1717 [switch ]$AllowUnsigned = $true
1818)
1919
20- # AMD OpenCL registry hives
2120$roots = @ (
22- " HKLM:\SOFTWARE\Khronos\OpenCL\Vendors" , # 64-bit
23- " HKLM:\SOFTWARE\WOW6432Node\Khronos\OpenCL\Vendors" # 32-bit
21+ " HKLM:\SOFTWARE\Khronos\OpenCL\Vendors" ,
22+ " HKLM:\SOFTWARE\WOW6432Node\Khronos\OpenCL\Vendors"
2423)
2524
26- # Standard AMD directories scanned for OpenCL ICDs
2725$scanDirs = @ (
2826 " $env: WINDIR \System32" ,
2927 " $env: WINDIR \SysWOW64" ,
@@ -37,42 +35,33 @@ function Get-DllBitness {
3735 try {
3836 $fs = [System.IO.File ]::Open($Path , ' Open' , ' Read' , ' Read' )
3937 $br = New-Object System.IO.BinaryReader($fs )
40-
41- # Read PE header offset
4238 $fs.Seek (0x3C , ' Begin' ) | Out-Null
4339 $peOffset = $br.ReadInt32 ()
44-
45- # Read machine field
4640 $fs.Seek ($peOffset + 4 , ' Begin' ) | Out-Null
4741 $machine = $br.ReadUInt16 ()
48-
4942 $br.Close (); $fs.Close ()
50-
5143 switch ($machine ) {
52- 0x8664 { return 64 } # AMD64
53- 0x014C { return 32 } # I386
44+ 0x8664 { return 64 }
45+ 0x014C { return 32 }
5446 default { return $null }
5547 }
5648 } catch { return $null }
5749}
5850
5951function Safe-Remove {
6052 param ($root , $name )
61- try {
62- Remove-ItemProperty - Path $root - Name $name - Force
63- } catch { $global :hadErrors = $true }
53+ try { Remove-ItemProperty - Path $root - Name $name - Force }
54+ catch { $global :hadErrors = $true }
6455}
6556
6657function Safe-Add {
6758 param ($root , $name )
68- try {
69- New-ItemProperty - Path $root - Name $name - Value 0 - PropertyType DWord - Force | Out-Null
70- } catch { $global :hadErrors = $true }
59+ try { New-ItemProperty - Path $root - Name $name - Value 0 - PropertyType DWord - Force | Out-Null }
60+ catch { $global :hadErrors = $true }
7161}
7262
7363function Is-SignatureAcceptable {
7464 param ($sig , $AllowUnsigned )
75-
7665 if ($sig.Status -eq ' Valid' ) { return $true }
7766 if ($AllowUnsigned -and ($sig.Status -eq ' NotSigned' -or $sig.Status -eq ' Unknown' )) {
7867 return $true
@@ -82,95 +71,71 @@ function Is-SignatureAcceptable {
8271
8372function Register-OpenCLDLL {
8473 param ([string ]$dllPath , [switch ]$AllowUnsigned )
85-
8674 if (-not (Test-Path $dllPath )) { return }
87-
8875 $sig = Get-AuthenticodeSignature - FilePath $dllPath
8976 if (-not (Is- SignatureAcceptable $sig $AllowUnsigned )) { return }
90-
9177 $bit = Get-DllBitness $dllPath
9278 if ($bit -eq 64 ) { $root = $roots [0 ] }
9379 elseif ($bit -eq 32 ) { $root = $roots [1 ] }
9480 else { return }
95-
9681 $exists = (Get-ItemProperty - Path $root - ErrorAction SilentlyContinue).PSObject.Properties |
9782 Where-Object { $_.Name -eq $dllPath }
98-
9983 if (-not $exists ) {
10084 Safe- Add $root $dllPath
101- Write-Host " Added ( $bit - bit) : $dllPath " - ForegroundColor Cyan
85+ Write-Host " [+ $bit bit] Added : $dllPath " - ForegroundColor Cyan
10286 }
10387}
10488
105- # ----------------------------------------------------------
106- # 1) SAFE CLEANUP
107- # ----------------------------------------------------------
108-
89+ # Registry cleanup: remove invalid, missing, or misplaced entries
10990foreach ($root in $roots ) {
110-
11191 Write-Host " `n Analyzing: $root " - ForegroundColor Cyan
112-
11392 $entries = Get-ItemProperty - Path $root - ErrorAction SilentlyContinue
11493 if (-not $entries ) {
11594 Write-Host " No entries found or key missing."
11695 continue
11796 }
118-
11997 foreach ($prop in $entries.PSObject.Properties ) {
120-
12198 $dll = $prop.Name
12299 if ($dll -notlike " *amdocl*.dll" ) { continue }
123-
124100 if (-not (Test-Path $dll )) {
125- Write-Host " Removed: $dll (file missing )" - ForegroundColor Yellow
101+ Write-Host " Removed: $dll (file not found )" - ForegroundColor Yellow
126102 Safe- Remove $root $dll
127103 continue
128104 }
129-
130105 $sig = Get-AuthenticodeSignature - FilePath $dll
131106 if (-not (Is- SignatureAcceptable $sig $AllowUnsigned )) {
132107 Write-Host " Removed: $dll (invalid signature)" - ForegroundColor Yellow
133108 Safe- Remove $root $dll
134109 continue
135110 }
136-
137111 $bit = Get-DllBitness $dll
138112 if ($bit -eq $null ) {
139- Write-Host " Removed: $dll (bitness not detectable )" - ForegroundColor Yellow
113+ Write-Host " Removed: $dll (architecture not detected )" - ForegroundColor Yellow
140114 Safe- Remove $root $dll
141115 continue
142116 }
143-
144117 $correctRoot = if ($bit -eq 64 ) { $roots [0 ] } else { $roots [1 ] }
145-
146118 if ($correctRoot -ne $root ) {
147- Write-Host " Fixed hive mismatch ($bit - bit): $dll " - ForegroundColor Yellow
119+ Write-Host " Moved ($bit bit): $dll " - ForegroundColor Yellow
148120 Safe- Remove $root $dll
149-
150121 $existsDest = (Get-ItemProperty - Path $correctRoot - ErrorAction SilentlyContinue).PSObject.Properties |
151122 Where-Object { $_.Name -eq $dll }
152-
153123 if (-not $existsDest ) {
154124 Safe- Add $correctRoot $dll
155125 }
156126 continue
157127 }
158-
159128 Write-Host " OK: $dll " - ForegroundColor Green
160129 }
161130}
162131
163- # ----------------------------------------------------------
164- # 2) COHERENT REBUILD (improved)
165- # ----------------------------------------------------------
166-
167- Write-Host " `n Rebuilding..." - ForegroundColor Cyan
132+ # Register all valid DLLs found in each directory (no duplicates)
133+ Write-Host " `n Registering all valid AMD OpenCL DLLs from standard directories..." - ForegroundColor Cyan
168134
169135foreach ($dir in $scanDirs ) {
170136 if (-not (Test-Path $dir )) { continue }
171-
172137 Get-ChildItem - Path $dir - Filter " amdocl*.dll" - Recurse - ErrorAction SilentlyContinue |
173- Sort -Object { $_.VersionInfo.FileVersionRaw } - Descending - ErrorAction SilentlyContinue |
138+ Where -Object { $_.VersionInfo.FileVersionRaw } |
174139 ForEach-Object {
175140 Register-OpenCLDLL - dllPath $_.FullName - AllowUnsigned:$AllowUnsigned
176141 }
@@ -179,7 +144,25 @@ foreach ($dir in $scanDirs) {
179144if ($hadErrors ) {
180145 Write-Host " `n Completed with warnings." - ForegroundColor Yellow
181146} else {
182- Write-Host " `n Completed successfully." - ForegroundColor Green
147+ Write-Host " `n Completed." - ForegroundColor Green
148+ }
149+
150+ # Optional PATH scan
151+ Write-Host " `n Do you want to include an extended scan of system PATH directories? (Recommended only for custom or unofficial DLLs)" - ForegroundColor Yellow
152+ $input = Read-Host " Type Y to scan, anything else to skip"
153+ if ($input -eq ' Y' -or $input -eq ' y' ) {
154+ Write-Host " `n Note: DLLs found in PATH may be unofficial or obsolete." - ForegroundColor Magenta
155+ $pathDirs = ($env: PATH -split ' ;' | Where-Object { Test-Path $_ })
156+ foreach ($dir in $pathDirs ) {
157+ Get-ChildItem - Path $dir - Filter " amdocl*.dll" - Recurse - ErrorAction SilentlyContinue |
158+ Where-Object { $_.VersionInfo.FileVersionRaw } |
159+ ForEach-Object {
160+ Register-OpenCLDLL - dllPath $_.FullName - AllowUnsigned:$AllowUnsigned
161+ }
162+ }
163+ Write-Host " `n PATH scan completed." - ForegroundColor Cyan
164+ } else {
165+ Write-Host " `n PATH scan skipped."
183166}
184167
185168Read-Host " Press Enter to exit"
0 commit comments