标题: [问题求助] VBS怎样对注册表循环读取? [打印本页]
作者: lqh123108 时间: 2014-9-10 10:35 标题: VBS怎样对注册表循环读取?
- Private Shared Sub GetVersionFromRegistry()
- Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
-
- For Each versionKeyName As String In ndpKey.GetSubKeyNames()
- If versionKeyName.StartsWith("v") Then
- Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName)
- Dim name As String = DirectCast(versionKey.GetValue("Version", ""), String)
- Dim sp As String = versionKey.GetValue("SP", "").ToString()
- Dim install As String = versionKey.GetValue("Install", "").ToString()
- If install = "" Then
- 'no install info, ust be later
- Console.WriteLine(versionKeyName & " " & name)
- Else
- If sp <> "" AndAlso install = "1" Then
- Console.WriteLine(versionKeyName & " " & name & " SP" & sp)
-
- End If
- End If
- If name <> "" Then
- Continue For
- End If
- For Each subKeyName As String In versionKey.GetSubKeyNames()
- Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
- name = DirectCast(subKey.GetValue("Version", ""), String)
- If name <> "" Then
- sp = subKey.GetValue("SP", "").ToString()
- End If
- install = subKey.GetValue("Install", "").ToString()
- If install = "" Then
- 'no install info, ust be later
- Console.WriteLine(versionKeyName & " " & name)
- Else
- If sp <> "" AndAlso install = "1" Then
- Console.WriteLine(" " & subKeyName & " " & name & " SP" & sp)
- ElseIf install = "1" Then
- Console.WriteLine(" " & subKeyName & " " & name)
-
- End If
- End If
- Next
- End If
- Next
- End Using
- End Sub
复制代码
这个是VB.NET ,能否改成VBS版本..
作者: czjt1234 时间: 2014-9-10 14:31
没看懂
解释下你要进行什么操作
作者: yu2n 时间: 2014-9-10 19:43
[原创] 读取、新建、修改、删除注册表键值专题帖
本帖最后由 batman 于 2012-12-26 00:02 编辑
http://www.bathome.net/thread-21223-1-1.html- '枚举注册表项及值
- Const HKEY_LOCAL_MACHINE = &H80000002
- Dim regWMI, FSO, Text
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set regWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
- Dim regRoot, regPath, regStr
- regRoot = HKEY_LOCAL_MACHINE
- regPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
- FSO.OpenTextFile("RegList.txt", 2, True).Write "HomePath:HKEY_LOCAL_MACHINE" & regPath & vbCrLf & vbcrlf & "RegList:" & vbCrLf
- Set Text = FSO.OpenTextFile("RegList.txt", 8, True)
- GetValues regPath
- GetKeys regPath
- Set FSO = Nothing
- Set regWMI = Nothing
- CreateObject("Wscript.Shell").run "cmd /cRegList.txt", True, False
-
- Function GetKeys(Path)
- 'Text.WriteLine path & vbCrLf
- Dim arrRegKeys, regKey
- regWMI.Enumkey regRoot, path, arrRegKeys
- For Each regKey In arrRegKeys
- On Error Resume Next
- newpath = path & "\" & regKey
- GetValues newpath
- GetKeys newpath
- Next
- End Function
-
- Function GetValues(path)
- Dim regValue, arrRegNames, arrValueTypes, arrRegValues, Multi, regValueType
- regWMI.EnumValues regRoot, path, arrRegNames, arrValueTypes
- For i = 0 To UBound(arrRegNames)
- If Len(arrRegNames(i)) > 0 Then
- Multi = vbNullString
- Select Case arrValueTypes(i)
- Case 1
- regWMI.GetStringValue regRoot, path, arrRegNames(i), regValue
- regValueType = "REG_SZ"
- Case 2
- regWMI.GetExpandedStringValue regRoot, path, arrRegNames(i), regValue
- regValueType = "REG_EXPAND_SZ"
- Case 3
- regWMI.GetBinaryValue regRoot, path, arrRegNames(i), regValue
- regValueType = "REG_BINARY"
- Case 4
- regWMI.GetDwordValue regRoot, path, arrRegNames(i), regValue
- regValueType = "REG_DWORD"
- Case 7
- regWMI.GetMultiValue regRoot, path, arrRegNames(i), arrRegValues
- regValueType = "REG_MULTI_SZ"
- Multi = "yes"
- End Select
- If Multi = "yes" Then
- For Each str In arrRegValues
- regValue = regValue & str & vbTab
- Next
- End If
- newpath = Replace(path, regPath, "")
- If Left(newpath, 1) = "\" Then newpath = Mid(newpath,2,Len(newpath))
- Text.WriteLine newpath & arrRegNames(i) & vbTab & regValueType & vbTab & regValue
- End If
- Next
- End Function
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |