回复 18# apang
是这样吗?- Dim fso, txt, re, m, regPath, regValue, regData
- Set fso = CreateObject("Scripting.FileSystemObject")
- txt = fso.OpenTextFile("HIVESFT.INF", 1, false, -1).ReadAll
- txt = txt & vbCrLf & "["
-
- Set re = New RegExp
- re.Pattern = "^ *\[Strings] *$[\s\S]*?(?=^ *\[)"
- re.IgnoreCase = true
- re.Global = true
- re.MultiLine = true
- If Not re.Test(txt) Then WScript.Quit
- txt = re.Execute(txt)(0)
- re.Pattern = "^ *(BIOS|NDIS|NETWORK_DDE|NETWORK_DDE_DESCRIPTION|NETWORK_DDE_DSDM) *= *(.+)"
- For Each m in re.Execute(txt)
- regData = Replace(m.SubMatches(1), chr(34), "")
- If UCase(m.SubMatches(0)) = "BIOS" Then
- regPath = "yyn\Desktop"
- regValue = "yyn1"
- End If
- If UCase(m.SubMatches(0)) = "NDIS" Then
- regPath = "yyn\Desktop\yyn"
- regValue = "yyn2"
- End If
- If UCase(m.SubMatches(0)) = "NETWORK_DDE" Then
- regPath = "yyn\Test"
- regValue = "yyn3"
- End If
- If UCase(m.SubMatches(0)) = "NETWORK_DDE_DESCRIPTION" Then
- regPath = "yyn\Test\yyn"
- regValue = "yyn4"
- End If
- If UCase(m.SubMatches(0)) = "NETWORK_DDE_DSDM" Then
- regPath = "yyn\yyn\yyn"
- regValue = "yyn5"
- End If
- WriteToRegValue regPath, regValue, regData
- Next
-
- Sub WriteToRegValue(ByVal regPath, ByVal regValue, ByVal regData)
- Const HKCU = &H80000001
- Dim regWMI
- Set regWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\Default:StdRegProv")
- regWMI.CreateKey HKCU, regPath1
- regWMI.SetStringValue HKCU, regPath, regValue, regData
- End Sub
复制代码 但提示:
另外,在 re.Pattern = "^ *(BIOS|NDIS|NETWORK_DDE|NETWORK_DDE_DESCRIPTION|NETWORK_DDE_DSDM) *= *(.+)" 中,如果需要几十个变量,该如何处理? |