Board logo

标题: [问题求助] 请教如何自动搜索并删除注册表含某关键词的项或键? [打印本页]

作者: suchost    时间: 2015-9-25 15:31     标题: 请教如何自动搜索并删除注册表含某关键词的项或键?

请高手指教,比如我要搜索MSOUC.EXE,并删除与之关联的所有项
作者: yu2n    时间: 2015-9-25 22:42

参考:
[原创] 读取、新建、修改、删除注册表键值专题帖
http://www.bathome.net/thread-21223-1-1.html
  1. '枚举注册表项及值
  2. Const HKEY_LOCAL_MACHINE = &H80000002
  3. Dim regWMI, FSO, Text
  4. Set FSO = CreateObject("Scripting.FileSystemObject")
  5. Set regWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  6. Dim regRoot, regPath, regStr
  7. regRoot = HKEY_LOCAL_MACHINE
  8. regPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
  9. FSO.OpenTextFile("RegList.txt", 2, True).Write "HomePath:HKEY_LOCAL_MACHINE" & regPath & vbCrLf & vbcrlf & "RegList:" & vbCrLf
  10. Set Text = FSO.OpenTextFile("RegList.txt", 8, True)
  11. GetValues regPath
  12. GetKeys regPath
  13. Set FSO = Nothing
  14. Set regWMI = Nothing
  15. CreateObject("Wscript.Shell").run "cmd /cRegList.txt", True, False
  16. Function GetKeys(Path)
  17.   'Text.WriteLine path & vbCrLf
  18.   Dim arrRegKeys, regKey
  19.   regWMI.Enumkey regRoot, path, arrRegKeys
  20.   For Each regKey In arrRegKeys
  21.     On Error Resume Next
  22.     newpath = path & "\" & regKey
  23.     GetValues newpath
  24.     GetKeys newpath
  25.   Next
  26. End Function
  27. Function GetValues(path)
  28.   Dim regValue, arrRegNames, arrValueTypes, arrRegValues, Multi, regValueType
  29.   regWMI.EnumValues regRoot, path, arrRegNames, arrValueTypes
  30.   For i = 0 To UBound(arrRegNames)
  31.     If Len(arrRegNames(i)) > 0 Then
  32.       Multi = vbNullString
  33.       Select Case arrValueTypes(i)
  34.         Case 1
  35.           regWMI.GetStringValue regRoot, path, arrRegNames(i), regValue
  36.           regValueType = "REG_SZ"
  37.         Case 2
  38.           regWMI.GetExpandedStringValue regRoot, path, arrRegNames(i), regValue
  39.           regValueType = "REG_EXPAND_SZ"
  40.         Case 3
  41.           regWMI.GetBinaryValue regRoot, path, arrRegNames(i), regValue
  42.           regValueType = "REG_BINARY"
  43.         Case 4
  44.           regWMI.GetDwordValue regRoot, path, arrRegNames(i), regValue
  45.           regValueType = "REG_DWORD"
  46.         Case 7
  47.           regWMI.GetMultiValue regRoot, path, arrRegNames(i), arrRegValues
  48.           regValueType = "REG_MULTI_SZ"
  49.           Multi = "yes"
  50.       End Select
  51.       If Multi = "yes" Then
  52.         For Each str In arrRegValues
  53.           regValue = regValue & str & vbTab
  54.         Next
  55.       End If
  56.       newpath = Replace(path, regPath, "")
  57.       If Left(newpath, 1) = "\" Then newpath = Mid(newpath,2,Len(newpath))
  58.       Text.WriteLine newpath & arrRegNames(i) & vbTab & regValueType & vbTab & regValue
  59.     End If
  60.   Next
  61. End Function
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2