我想删除所有包含 1000+
的键( Python35
)来自:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components
例如,我想删除与该键类似的所有键:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components\0027CAECCC428F356B8D845FF8331246
0F617A7B1C879BC47865E0155CDD6722
C:\Users\Me\AppData\Local\Programs\Python\Python35\Lib\venv\__init__.py
我试过这个。
Get-ChildItem -path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components\ -Recurse | where { $_.Name -match 'Python35'} | Remove-Item -Force
Powershell 运行没有错误,但是当我在注册表中检查它时, key 仍然存在。
Powershell 以管理员身份运行,管理员拥有 key
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components
的所有权。并完全控制该键及其子键。
最佳答案
尝试以下脚本:
$RE = 'Python35'
$Key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-2\Components'
Get-ChildItem $Key -Rec -EA SilentlyContinue | ForEach-Object {
$CurrentKey = (Get-ItemProperty -Path $_.PsPath)
If ($CurrentKey -match $RE){
$CurrentKey|Remove-Item -Force -Whatif
}
}
如果输出看起来正常,请删除 -WhatIf
来自 Remove-Item
的参数
关于Powershell:删除所有包含字符串的注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44196938/