如何删除具有随机名称的注册表属性

问题描述 投票:1回答:2

我正在尝试删除多台计算机中广告软件中留下的垃圾注册表项。广告软件在以下路径中创建了注册表项:

HKEY_LOCAL_MACHINE \ SYSTEM \ ControlSet001 \ Services \

属性:机器之间的随机名称不同

值:机器之间相同的恶意字符串

Get-ChildItem -path HKLM:\System\Controlset001\Services | 
  Get-ItemProperty |
    Where-Object {$_.ValueName -eq "Value"} |
      Remove-ItemProperty -ErrorAction SilentlyContinue

我已经知道了子键和属性,因此尝试了上述方法删除键,但是由于属性是随机的,所以没有任何结果。非常感谢!

powershell
2个回答
0
投票

这是get-itemproperty的替代脚本:

# get-itemproperty2.ps1
param([parameter(ValueFromPipeline)]$key)
process { 
  $key.getvaluenames() |
  foreach {
    $value = $_
    [pscustomobject] @{
      Path = $key -replace 'HKEY_CURRENT_USER',
        'HKCU:' -replace 'HKEY_LOCAL_MACHINE','HKLM:'
      Name = $Value
      Value = $Key.GetValue($Value)
      Type = $Key.GetValueKind($Value)
    }
  }
}

因此您可以执行以下操作:

Get-ChildItem HKLM:\System\Controlset001\Services | .\Get-ItemProperty2 |
  Where Value -eq MyValue | Remove-ItemProperty -Whatif

0
投票

尝试以下操作:

# Specify whatever fixed value the malware stored in the 'ImagePath'
# property of the randomly named keys.
$propValue = '...'

Get-ChildItem -LiteralPath HKLM:\System\ControlSet001\Services |
  Where-Object { $_.GetValue('ImagePath') -eq $propValue } |
    Remove-Item -WhatIf

注:Common parameter -WhatIf 预览操作;删除它以执行实际操作。

  • -WhatIf枚举指定路径的所有子项。

  • Get-ChildItem -LiteralPath HKLM:\System\ControlSet001\Services仅选择其Where-Object { $_.GetValue('ImagePath') -eq $propValue }属性具有指定值的那些子项。

  • [ImagePath然后删除选定的子项。

© www.soinside.com 2019 - 2024. All rights reserved.