标题: [问题求助] VBS如何遍历指定注册表路径下的键值项和键值? [打印本页]
作者: 1078292299 时间: 2021-1-28 11:44 标题: VBS如何遍历指定注册表路径下的键值项和键值?
用VBS如何把 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion 右边的键值项和键值遍历MsgBox输出?
作者: WHY 时间: 2021-1-28 21:40
本帖最后由 WHY 于 2021-1-28 22:34 编辑
- Rem On Error Resume Next
- Const HKLM = &H80000002
- Dim regPath, objReg
- regPath = "Software\Microsoft\Windows\CurrentVersion"
- Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\Root\Default:StdRegProv")
-
- EnumRegistry HKLM, regPath
-
- Function EnumRegistry(HKLM, regSubPath)
- Dim arrName, arrType, s, i, regType, regValue
- objReg.EnumValues HKLM, regSubPath, arrName, arrType '枚举注册表值名
- If isArray(arrName) Then
- s = ""
- For i=0 To UBound(arrName)
- regType = GetRegType(arrType(i)) '获取类型
- regValue = GetRegValue( HKLM, regSubPath, arrName(i), arrType(i) ) '获取注册表值
- s = s & arrName(i) & vbTab & regType & vbTab & regValue & vbLf
- Next
- WSH.Echo regSubPath & vbLf & s
- Else
- WSH.Echo regSubPath
- End If
-
- objReg.EnumKey HKLM, regSubPath, arrName '枚举注册表项
- If isArray(arrName) Then
- For i=0 To UBound(arrName)
- EnumRegistry HKLM, regSubPath & "\" & arrName(i) '递归
- Next
- End If
- End Function
-
- Function GetRegType(n)
- Select Case n
- Case 1 GetRegType = "REG_SZ"
- Case 2 GetRegType = "REG_EXPAND_SZ"
- Case 3 GetRegType = "REG_BINARY"
- Case 4 GetRegType = "REG_DWORD"
- Case 7 GetRegType = "REG_MULTI_SZ"
- Case 11 GetRegType = "REG_QWORD"
- End Select
- End Function
-
- Function GetRegValue( HKLM, regSubPath, regName, n )
- Select Case n
- Case 1
- objReg.GetStringValue HKLM, regSubPath, regName, sValue
- GetRegValue = sValue
- Case 2
- objReg.GetExpandedStringValue HKLM, regSubPath, regName, sValue
- GetRegValue = sValue
- Case 3
- objReg.GetBinaryValue HKLM, regSubPath, regName, uValue
- GetRegValue = Join(uValue, ",")
- Case 4
- objReg.GetDWORDValue HKLM, regSubPath, regName, uValue
- GetRegValue = uValue
- Case 7
- objReg.GetMultiStringValue HKLM, regSubPath, regName, sValue
- GetRegValue = Join(sValue, ",")
- Case 11
- objReg.GetQWORDValue HKLM, regSubPath, regName, uValue
- GetRegValue = uValue
- End Select
- End Function
复制代码
作者: 1078292299 时间: 2021-1-29 15:17
大哥牛皮,666
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |