Board logo

标题: [文本处理] 求助,给注册表文件加注释的批处理 [打印本页]

作者: newswan    时间: 2012-10-13 22:48     标题: 求助,给注册表文件加注释的批处理

注册表文件里有这样的项
"LowerFilters"=hex(7):75,00,77,00,66,00,76,00,6f,00,6c,00,00,00,66,00,76,00,65,\
  00,76,00,6f,00,6c,00,00,00,72,00,64,00,79,00,62,00,6f,00,6f,00,73,00,74,00,\
  00,00,00,00
"ImagePath"=hex(2):73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,64,00,\
  72,00,69,00,76,00,65,00,72,00,73,00,5c,00,75,00,77,00,66,00,73,00,2e,00,73,\
  00,79,00,73,00,00,00

不方便阅读,需要给出注释,
hex(7) = REG_MULTI_SZ
hex(2) = REG_EXPAND_SZ
75,00 = u
hex(7)中
00,00 = 换行
00,00,00,00  = 结束

hex(2)中
00,00 = 结束

在注册表文件中,对应的下面添加如下注释
;REG_MULTI_SZ    uwfvol\0fvevol\0rdyboost
;REG_EXPAND_SZ    %SystemRoot%\system32\wbem\uwfwmi.dll

求帮忙,谢谢
作者: 冷玉公子    时间: 2012-10-14 01:09

hex 是字符的16进制编码,可以试试把编码还原成原始字符串。
问题应该8是很大。论坛搜索一下字符的转换。
作者: apang    时间: 2012-10-14 22:35

与楼主要求有点出入,只当是新手练习。。。
  1. Set FSO = CreateObject("Scripting.FileSystemObject")
  2. Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
  3. Set oFile = FSO.OpenTextFile("aa.reg",2,True,-1)
  4. Do Until sFile.AtEndOfStream
  5.    sLine = sFile.ReadLine
  6.    Set Re = New RegExp
  7.    Re.Pattern = "[0-9a-f]{2},"
  8.    Re.Global = True
  9.    Re.IgnoreCase = True
  10.    For Each Match In Re.Execute(sLine)
  11.       oLine = oLine & Chr("&H" & Left(Match,2))
  12.    Next
  13.    oFile.WriteLine sLine
  14.    If oLine <> "" Then
  15.       oFile.WriteLine ";" & oLine
  16.    End If
  17.    oLine = ""
  18. Loop
复制代码

作者: newswan    时间: 2012-10-15 07:13

谢谢,
再修改一下
一个字符紧跟的一个空格 删除
连续三个空格转换为回车
  1. Set FSO = CreateObject("Scripting.FileSystemObject")
  2. Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
  3. Set oFile = FSO.OpenTextFile("uwf.txt",2,True,-1)
  4. Do Until sFile.AtEndOfStream
  5.    sLine = sFile.ReadLine
  6.    oFile.WriteLine sLine
  7.    Set R7 = New RegExp
  8.    R7.Pattern = "[hex(7):]{7}"
  9.    R7.Global = True
  10.    R7.IgnoreCase = True
  11.    For Each Match In R7.Execute(sLine)
  12.       oLine = ";M   "
  13.    Next
  14.    Set R2 = New RegExp
  15.    R2.Pattern = "[hex(2):]{7}"
  16.    R2.Global = True
  17.    R2.IgnoreCase = True
  18.    For Each Match In R2.Execute(sLine)
  19.       oLine = ";E   "
  20.    Next
  21.    Set Re = New RegExp
  22.    Re.Pattern = "[0-9a-f]{2},"
  23.    Re.Global = True
  24.    Re.IgnoreCase = True
  25.    For Each Match In Re.Execute(sLine)
  26.       if Left(Match,2) = "00" Then Match = 20
  27.   oLine = oLine & Chr("&H" & Left(Match,2))
  28.    Next
  29.    if Right(sLine,1) <> "\" Then
  30.    If oLine <> "" Then
  31.   oFile.WriteLine oLine
  32.           oLine = ""
  33.    End If
  34.    End If
  35. Loop
复制代码

作者: newswan    时间: 2012-10-16 14:20

Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
Set oFile = FSO.OpenTextFile("uwf.txt",2,True,-1)

请问,怎么用窗口选定 输入输出文件
作者: apang    时间: 2012-10-16 16:20

本帖最后由 apang 于 2012-10-16 19:29 编辑

回复 5# newswan
  1. Set objDialog = CreateObject("UserAccounts.CommonDialog")
  2. objDialog.Filter = "Reg File|*.reg|Txt File|*.txt"
  3. objDialog.InitialDir = "."
  4. If Not objDialog.ShowOpen Then MsgBox "未选择" : WScript.Quit
  5. MsgBox "所选文件为:" & vbCrLf & objDialog.FileName
复制代码
测试XP能行,但Win7不支持创建该对象
作者: newswan    时间: 2012-10-16 20:55

win8,也不行。
谢谢
作者: newswan    时间: 2012-10-16 20:56

暂时就这样吧。
谢谢大家。
  1. Set FSO = CreateObject("Scripting.FileSystemObject")
  2. Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
  3. Set oFile = FSO.OpenTextFile("uwf.txt",2,True,-1)
  4. Do Until sFile.AtEndOfStream
  5. sLine = RTrim(sFile.ReadLine)
  6. oFile.WriteLine sLine
  7. if instr(sLine,"hex(") <> 0 then
  8. mLine = mid(sLine,instr(sLine,"hex(")+7)
  9. if mid(sLine,instr(sLine,"hex(")+4,1) = "7" then oLinef = ";M   "
  10. if mid(sLine,instr(sLine,"hex(")+4,1) = "2" then oLinef = ";E   "
  11. oLine = ""
  12. do while len(mLine) > 5
  13. if Left(mLine,2) = "00" Then
  14. oLine = oLine & Chr(32)
  15. else
  16. oLine = oLine & Chr("&H" & Left(mLine,2))
  17. end if
  18. mLine = right(mLine,len(mLine)-6)
  19. if len(mLine) <= 4 and right(mLine,1) = "\" then
  20. sLine = RTrim(sFile.ReadLine)
  21. oFile.WriteLine sLine
  22. mLine = left(mLine,len(mLine)-1) & Trim(sLine)
  23. end if
  24. loop
  25. if Left(mLine,2) = "00" Then
  26. oLine = oLine & Chr(32)
  27. else
  28. oLine = oLine & Chr("&H" & Left(mLine,2))
  29. end if
  30. oLine = trim(oLine)
  31. if instr(oLinef,"E") <> 0 then oFile.WriteLine oLinef & oLine
  32. if instr(oLinef,"M") <> 0 then
  33. do
  34. if instr(oLine," ") = 0 then
  35. oFile.WriteLine oLinef & oLine
  36. oLine = ""
  37. else
  38. oFile.WriteLine oLinef & left(oLine,instr(oLine," ")-1)
  39. oLine = mid(oLine,instr(oLine," ")+1)
  40. end if
  41. loop while len(oLine) > 0
  42. end if
  43. end if
  44. Loop
复制代码

作者: newswan    时间: 2012-10-16 20:57

顺便问下,vbs编辑器,哪个好些?我用的notepad++




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