本文介绍了如何从根迭代注册表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在所有注册表(HKEY_CLASSES_ROOT、HKEY_CURRENT_USER、HKEY_LOCAL_MACHINE、HKEY_USERS 和所有子项)中搜索特定值,如果有匹配项,我想删除此条目.有没有办法做到这一点?我找到了一个如下所示的示例,但它没有迭代所有注册表.
I would like to search all the registry (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS and all of the subkeys) for a specific value and if there is a match I would like to delete this entry. Is there a way to do this? I found a sample like below but it is not iterating all the registry.
在此致以最好的问候和感谢.
Best Regards and thanks in advance.
Const HKCU = &H80000001
Const HKLM = &H80000002
Const HKU = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
valueToDelete = "Alex De Souza"
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
Sub DeleteFromRegistry(hive, key, searchValue)
'enumerate values and delete matching ones
rc = reg.EnumValues(hive, key, values, types)
If Not IsNull(values) Then
For i = LBound(values) To UBound(values)
strValueName = values(i)
Select Case types(i)
' Show a REG_SZ value
'
Case REG_SZ
reg.GetStringValue hive, key, strValueName, strValue
If InStr(strValue, searchValue) > 0 Then
wscript.echo "Found " & key & ": "& strValueName & " (REG_SZ) = " & strValue
rc = reg.DeleteValue(hive, key, strValue)
End If
' Show a REG_EXPAND_SZ value
'
Case REG_EXPAND_SZ
reg.GetExpandedStringValue hive, key, strValueName, strValue
If InStr(strValue, searchValue) > 0 Then
wscript.echo "Found "& key & ": " & strValueName & " REG_EXPAND_SZ) = " & strValue
rc = reg.DeleteValue(hive, key, strValue)
End If
' Show a REG_DWORD value
'
Case REG_DWORD
reg.GetDWORDValue hive, key, strValueName, uValue
If InStr(strValue, searchValue) > 0 Then
wscript.echo "Found "& key & ": " & strValueName & " (REG_DWORD) = " & strValue
rc = reg.DeleteValue(hive, key, strValue)
End If
End Select
Next
End If
'enumerate subkeys and recurse
rc = reg.EnumKey(hive, key, subkeys)
If Not IsNull(subkeys) Then
For Each sk In subkeys
If key = "" Then
path = sk
Else
path = key & "\" & sk
End If
DeleteFromRegistry hive, path, searchValue
Next
End If
End Sub
'iterate over hives (HKCR can be ignored, because it's just a combining view
'on 2 subkeys of HKLM and HKCU)
For Each hive In Array(HKCU, HKLM, HKU)
DeleteFromRegistry hive, "", valueToDelete
Next
推荐答案
您需要一个递归过程.
Const HKCU = &H80000001
Const HKLM = &H80000002
Const HKU = &H80000003
valueToDelete = "..."
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
Sub DeleteFromRegistry(hive, key, searchValue)
'enumerate values and delete matching ones
rc = reg.EnumValues(hive, key, values, types)
If Not IsNull(values) Then
For Each val In values
If val = searchValue Then rc = reg.DeleteValue(hive, key, val)
Next
End If
'enumerate subkeys and recurse
rc = reg.EnumKey(hive, key, subkeys)
If Not IsNull(subkeys) Then
For Each sk In subkeys
If key = "" Then
path = sk
Else
path = key & "\" & sk
End If
DeleteFromRegistry hive, path, valueToDelete
Next
End If
End Sub
'iterate over hives (HKCR can be ignored, because it's just a combining view
'on 2 subkeys of HKLM and HKCU)
For Each hive In Array(HKCU, HKLM, HKU)
DeleteFromRegistry hive, "", valueToDelete
Next
这篇关于如何从根迭代注册表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!