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

[文本处理] 求助,给注册表文件加注释的批处理

注册表文件里有这样的项
"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

求帮忙,谢谢

hex 是字符的16进制编码,可以试试把编码还原成原始字符串。
问题应该8是很大。论坛搜索一下字符的转换。

TOP

与楼主要求有点出入,只当是新手练习。。。
  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
复制代码

TOP

谢谢,
再修改一下
一个字符紧跟的一个空格 删除
连续三个空格转换为回车
  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
复制代码

TOP

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

请问,怎么用窗口选定 输入输出文件

TOP

本帖最后由 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不支持创建该对象

TOP

win8,也不行。
谢谢

TOP

暂时就这样吧。
谢谢大家。
  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
复制代码

TOP

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

TOP

返回列表