[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] VBS如何遍历指定注册表路径下的键值项和键值?

用VBS如何把 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion 右边的键值项和键值遍历MsgBox输出?

本帖最后由 WHY 于 2021-1-28 22:34 编辑
  1. Rem On Error Resume Next
  2. Const HKLM = &H80000002
  3. Dim regPath, objReg
  4. regPath = "Software\Microsoft\Windows\CurrentVersion"
  5. Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\Root\Default:StdRegProv")
  6. EnumRegistry HKLM, regPath
  7. Function EnumRegistry(HKLM, regSubPath)
  8.     Dim arrName, arrType, s, i, regType, regValue
  9.     objReg.EnumValues HKLM, regSubPath, arrName, arrType                         '枚举注册表值名
  10.     If isArray(arrName) Then
  11.         s = ""
  12.         For i=0 To UBound(arrName)
  13.             regType  = GetRegType(arrType(i))                                    '获取类型
  14.             regValue = GetRegValue( HKLM, regSubPath, arrName(i), arrType(i) )   '获取注册表值
  15.             s = s & arrName(i) & vbTab & regType & vbTab & regValue & vbLf
  16.         Next
  17.         WSH.Echo regSubPath & vbLf & s
  18.     Else
  19.         WSH.Echo regSubPath
  20.     End If
  21.     objReg.EnumKey HKLM, regSubPath, arrName                                     '枚举注册表项
  22.     If isArray(arrName) Then
  23.         For i=0 To UBound(arrName)
  24.             EnumRegistry HKLM, regSubPath & "\" & arrName(i)    '递归
  25.         Next
  26.     End If
  27. End Function
  28. Function GetRegType(n)
  29.     Select Case n
  30.         Case 1 GetRegType = "REG_SZ"
  31.         Case 2 GetRegType = "REG_EXPAND_SZ"
  32.         Case 3 GetRegType = "REG_BINARY"
  33.         Case 4 GetRegType = "REG_DWORD"
  34.         Case 7 GetRegType = "REG_MULTI_SZ"
  35.         Case 11 GetRegType = "REG_QWORD"
  36.     End Select
  37. End Function
  38. Function GetRegValue( HKLM, regSubPath, regName, n )
  39.     Select Case n
  40.         Case 1
  41.             objReg.GetStringValue HKLM, regSubPath, regName, sValue
  42.             GetRegValue = sValue
  43.         Case 2
  44.             objReg.GetExpandedStringValue HKLM, regSubPath, regName, sValue
  45.             GetRegValue = sValue
  46.         Case 3
  47.             objReg.GetBinaryValue HKLM, regSubPath, regName, uValue
  48.             GetRegValue = Join(uValue, ",")
  49.         Case 4
  50.             objReg.GetDWORDValue HKLM, regSubPath, regName, uValue
  51.             GetRegValue = uValue
  52.         Case 7
  53.             objReg.GetMultiStringValue HKLM, regSubPath, regName, sValue
  54.             GetRegValue = Join(sValue, ",")
  55.         Case 11
  56.             objReg.GetQWORDValue HKLM, regSubPath, regName, uValue
  57.             GetRegValue = uValue
  58.     End Select
  59. End Function
复制代码
1

评分人数

TOP

大哥牛皮,666

TOP

返回列表