xlazom00

DisableProcessWatcherSupport.ps1

Oct 4th, 2026
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. #Requires -Version 5.1
  2. <#
  3. .SYNOPSIS
  4. Disables AMD's process watcher for the currently installed display driver.
  5. .DESCRIPTION
  6. Resolves each present AMD PCI display device to its current display-class key
  7. and service. No driver version, class instance number or service suffix is
  8. hardcoded. Run again after driver updates, because AMD may create a new service.
  9. Run in an elevated PowerShell. Use -WhatIf for read-only discovery.
  10. Backups and results are saved under mem\amd-process-watcher beside this script.
  11. The script never restarts Windows, Docker or the graphics device.
  12. .EXAMPLE
  13. .\DisableProcessWatcherSupport.ps1
  14. .EXAMPLE
  15. .\DisableProcessWatcherSupport.ps1 -WhatIf
  16. #>
  17. [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')]
  18. param()
  19.  
  20. $ErrorActionPreference='Stop'
  21. $valueName='Gmx_MgpuProcessWatcherSupport'
  22. $displayClass='{4d36e968-e325-11ce-bfc1-08002be10318}'
  23. $principal=New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())
  24. if(-not $WhatIfPreference -and -not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){
  25. throw 'Run this script in PowerShell as Administrator. Use -WhatIf for discovery without changes.'
  26. }
  27.  
  28. # Device -> Enum\PCI binding -> current display-class instance -> active service.
  29. # Enumerating service names alone would include obsolete driver installations.
  30. $devices=@(Get-CimInstance Win32_PnPEntity -Filter "PNPClass = 'Display'" |
  31. Where-Object {$_.PNPDeviceID -match '^PCI\\VEN_1002&' -and $_.Present -ne $false})
  32. if(-not $devices.Count){throw 'No present AMD PCI display device was found.'}
  33. $targets=@{}
  34. foreach($device in $devices){
  35. $enumKey='HKLM:\SYSTEM\CurrentControlSet\Enum\'+$device.PNPDeviceID
  36. $binding=Get-Item -LiteralPath $enumKey
  37. if([string]$binding.GetValue('ClassGUID') -ine $displayClass){throw ('Unexpected device class: '+$device.PNPDeviceID)}
  38. $classReference=[string]$binding.GetValue('Driver')
  39. if($classReference -notmatch ('^'+[regex]::Escape($displayClass)+'\\[0-9]+$')){
  40. throw ('The display device has no valid current class-instance binding: '+$device.PNPDeviceID)
  41. }
  42. $classKey='HKLM:\SYSTEM\CurrentControlSet\Control\Class\'+$classReference
  43. # Read only the needed values; unrelated AMD class values can have malformed
  44. # registry types that make Get-ItemProperty over the entire key fail.
  45. $class=Get-Item -LiteralPath $classKey
  46. $provider=[string]$class.GetValue('ProviderName')
  47. if($provider -notmatch 'AMD|Advanced Micro Devices'){
  48. throw ('The active display driver is not supplied by AMD: '+$classKey)
  49. }
  50. $service=[string]$binding.GetValue('Service')
  51. if($service -notmatch '^[a-zA-Z0-9_.-]+$'){throw 'The active AMD device has no valid service binding.'}
  52. $serviceKey='HKLM:\SYSTEM\CurrentControlSet\Services\'+$service
  53. $serviceInfo=Get-Item -LiteralPath $serviceKey
  54. $imagePath=[string]$serviceInfo.GetValue('ImagePath')
  55. if([string]::IsNullOrWhiteSpace($imagePath)){
  56. throw ('The current AMD service has no driver image: '+$service)
  57. }
  58. if(-not $targets.ContainsKey($service)){
  59. $targets[$service]=[ordered]@{
  60. Service=$service;Key=$serviceKey+'\Parameters';Name=$valueName
  61. ImagePath=$imagePath;Devices=@()
  62. }
  63. }
  64. $targets[$service].Devices+=,[ordered]@{
  65. Name=$device.Name;InstanceId=$device.PNPDeviceID;DisplayClassKey=$classKey
  66. DriverVersion=[string]$class.GetValue('DriverVersion');InfPath=[string]$class.GetValue('InfPath')
  67. ProviderName=$provider
  68. }
  69. }
  70.  
  71. $runDirectory=$null
  72. $results=New-Object 'System.Collections.Generic.List[object]'
  73. foreach($target in @($targets.Values|Sort-Object Service)){
  74. Write-Host ('AMD service: '+$target.Service)
  75. foreach($device in $target.Devices){Write-Host (' '+$device.Name+' -> '+$device.DisplayClassKey)}
  76. if(-not $PSCmdlet.ShouldProcess(($target.Key+'\'+$valueName),'Set REG_DWORD to 0')){continue}
  77. if(-not $runDirectory){
  78. $runDirectory=Join-Path $PSScriptRoot ('mem\amd-process-watcher\'+[datetime]::UtcNow.ToString('yyyyMMdd-HHmmss-fff')+'-'+[guid]::NewGuid().ToString('N').Substring(0,8))
  79. New-Item -ItemType Directory -Path $runDirectory -Force|Out-Null
  80. }
  81. $keyExists=Test-Path -LiteralPath $target.Key
  82. $item=if($keyExists){Get-Item -LiteralPath $target.Key}else{$null}
  83. $exists=$keyExists -and ($item.GetValueNames() -contains $valueName)
  84. $before=[ordered]@{
  85. Service=$target.Service;Key=$target.Key;Name=$valueName;KeyExisted=$keyExists
  86. ValueExisted=$exists;Kind=$null;Value=$null;Devices=$target.Devices
  87. ImagePath=$target.ImagePath;Utc=[datetime]::UtcNow.ToString('o')
  88. }
  89. if($exists){$before.Kind=$item.GetValueKind($valueName).ToString();$before.Value=$item.GetValue($valueName)}
  90. $backup=Join-Path $runDirectory ($target.Service+'-before.json')
  91. $before|ConvertTo-Json -Depth 7|Set-Content -LiteralPath $backup -Encoding UTF8
  92. $result=[ordered]@{Service=$target.Service;Key=$target.Key;Name=$valueName;Kind='DWord';Value=0;Changed=$false;Verified=$false;Backup=$backup;Error=$null}
  93. try{
  94. if(-not ($exists -and $before.Kind -eq 'DWord' -and $before.Value -eq 0)){
  95. if(-not $keyExists){New-Item -Path $target.Key -Force|Out-Null}
  96. New-ItemProperty -LiteralPath $target.Key -Name $valueName -PropertyType DWord -Value 0 -Force|Out-Null
  97. $result.Changed=$true
  98. }
  99. $after=Get-Item -LiteralPath $target.Key
  100. if(-not ($after.GetValueNames() -contains $valueName) -or $after.GetValueKind($valueName).ToString() -ne 'DWord' -or $after.GetValue($valueName) -ne 0){
  101. throw ('Registry verification failed: '+$target.Key)
  102. }
  103. $result.Verified=$true
  104. Write-Host ('Verified REG_DWORD 0: '+$target.Key+'\'+$valueName)
  105. }catch{$result.Error=$_.Exception.ToString();throw}
  106. finally{
  107. $results.Add([pscustomobject]$result)
  108. $results|ConvertTo-Json -Depth 7|Set-Content -LiteralPath (Join-Path $runDirectory 'result.json') -Encoding UTF8
  109. }
  110. }
  111. if($runDirectory){
  112. Write-Host ('Backup and verification: '+$runDirectory)
  113. Write-Host 'Restart Windows yourself to reload the driver setting. No restart was performed.'
  114. $results
  115. }
  116.  
Advertisement