标题: [文本处理] 求助,给注册表文件加注释的批处理 [打印本页]
作者: 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
与楼主要求有点出入,只当是新手练习。。。- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
- Set oFile = FSO.OpenTextFile("aa.reg",2,True,-1)
- Do Until sFile.AtEndOfStream
- sLine = sFile.ReadLine
- Set Re = New RegExp
- Re.Pattern = "[0-9a-f]{2},"
- Re.Global = True
- Re.IgnoreCase = True
- For Each Match In Re.Execute(sLine)
- oLine = oLine & Chr("&H" & Left(Match,2))
- Next
- oFile.WriteLine sLine
- If oLine <> "" Then
- oFile.WriteLine ";" & oLine
- End If
- oLine = ""
- Loop
复制代码
作者: newswan 时间: 2012-10-15 07:13
谢谢,
再修改一下
一个字符紧跟的一个空格 删除
连续三个空格转换为回车- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
- Set oFile = FSO.OpenTextFile("uwf.txt",2,True,-1)
-
- Do Until sFile.AtEndOfStream
- sLine = sFile.ReadLine
- oFile.WriteLine sLine
-
- Set R7 = New RegExp
- R7.Pattern = "[hex(7):]{7}"
- R7.Global = True
- R7.IgnoreCase = True
- For Each Match In R7.Execute(sLine)
- oLine = ";M "
- Next
-
- Set R2 = New RegExp
- R2.Pattern = "[hex(2):]{7}"
- R2.Global = True
- R2.IgnoreCase = True
- For Each Match In R2.Execute(sLine)
- oLine = ";E "
- Next
-
- Set Re = New RegExp
- Re.Pattern = "[0-9a-f]{2},"
- Re.Global = True
- Re.IgnoreCase = True
- For Each Match In Re.Execute(sLine)
- if Left(Match,2) = "00" Then Match = 20
- oLine = oLine & Chr("&H" & Left(Match,2))
- Next
-
- if Right(sLine,1) <> "\" Then
- If oLine <> "" Then
- oFile.WriteLine oLine
- oLine = ""
- End If
- End If
-
- 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 - Set objDialog = CreateObject("UserAccounts.CommonDialog")
- objDialog.Filter = "Reg File|*.reg|Txt File|*.txt"
- objDialog.InitialDir = "."
- If Not objDialog.ShowOpen Then MsgBox "未选择" : WScript.Quit
- MsgBox "所选文件为:" & vbCrLf & objDialog.FileName
复制代码
测试XP能行,但Win7不支持创建该对象
作者: newswan 时间: 2012-10-16 20:55
win8,也不行。
谢谢
作者: newswan 时间: 2012-10-16 20:56
暂时就这样吧。
谢谢大家。- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set sFile = FSO.OpenTextFile("uwf.reg",1,False,-1)
- Set oFile = FSO.OpenTextFile("uwf.txt",2,True,-1)
-
- Do Until sFile.AtEndOfStream
- sLine = RTrim(sFile.ReadLine)
- oFile.WriteLine sLine
-
- if instr(sLine,"hex(") <> 0 then
- mLine = mid(sLine,instr(sLine,"hex(")+7)
- if mid(sLine,instr(sLine,"hex(")+4,1) = "7" then oLinef = ";M "
- if mid(sLine,instr(sLine,"hex(")+4,1) = "2" then oLinef = ";E "
- oLine = ""
- do while len(mLine) > 5
- if Left(mLine,2) = "00" Then
- oLine = oLine & Chr(32)
- else
- oLine = oLine & Chr("&H" & Left(mLine,2))
- end if
- mLine = right(mLine,len(mLine)-6)
- if len(mLine) <= 4 and right(mLine,1) = "\" then
- sLine = RTrim(sFile.ReadLine)
- oFile.WriteLine sLine
- mLine = left(mLine,len(mLine)-1) & Trim(sLine)
- end if
- loop
- if Left(mLine,2) = "00" Then
- oLine = oLine & Chr(32)
- else
- oLine = oLine & Chr("&H" & Left(mLine,2))
- end if
- oLine = trim(oLine)
- if instr(oLinef,"E") <> 0 then oFile.WriteLine oLinef & oLine
- if instr(oLinef,"M") <> 0 then
- do
- if instr(oLine," ") = 0 then
- oFile.WriteLine oLinef & oLine
- oLine = ""
- else
- oFile.WriteLine oLinef & left(oLine,instr(oLine," ")-1)
- oLine = mid(oLine,instr(oLine," ")+1)
- end if
- loop while len(oLine) > 0
- end if
- end if
- Loop
复制代码
作者: newswan 时间: 2012-10-16 20:57
顺便问下,vbs编辑器,哪个好些?我用的notepad++
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |