标题: [问题求助] [已解决]---VBS 替换注册表文件中的内容 [打印本页]
作者: yuanyannian 时间: 2014-10-11 21:37 标题: [已解决]---VBS 替换注册表文件中的内容
本帖最后由 yuanyannian 于 2014-10-19 14:07 编辑
这个有点麻烦,求助高手老师们。
原文件如下:是后缀为 .reg 的注册表文件。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\pe-def\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
"AppData"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,41,00,70,00,70,00,6c,00,69,00,63,00,61,00,74,00,69,\
00,6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,00,00
"Desktop"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,4c,68,62,97,00,00
"Favorites"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,46,00,61,00,76,00,6f,00,72,00,69,00,74,00,65,00,73,\
00,00,00
"NetHood"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,4e,00,65,00,74,00,48,00,6f,00,6f,00,64,00,00,00
"ersonal"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,4d,00,79,00,20,00,44,00,6f,00,63,00,75,00,6d,00,65,\
00,6e,00,74,00,73,00,00,00
"PrintHood"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,50,00,72,00,69,00,6e,00,74,00,48,00,6f,00,6f,00,64,\
00,00,00
"Programs"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,0c,30,00,5f,cb,59,0d,30,dc,83,55,53,5c,00,0b,7a,8f,\
5e,00,00
"Recent"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,5c,00,52,00,65,00,63,00,65,00,6e,00,74,00,00,00
"SendTo"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,5c,00,53,00,65,00,6e,00,64,00,54,00,6f,00,00,00
"Start Menu"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,\
00,4c,00,45,00,25,00,5c,00,0c,30,00,5f,cb,59,0d,30,dc,83,55,53,00,00
"Startup"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,0c,30,00,5f,cb,59,0d,30,dc,83,55,53,5c,00,0b,7a,8f,\
5e,5c,00,2f,54,a8,52,00,00
"Templates"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,54,00,65,00,6d,00,70,00,6c,00,61,00,74,00,65,00,73,\
00,00,00
"Cookies"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,43,00,6f,00,6f,00,6b,00,69,00,65,00,73,00,00,00
"My Pictures"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,\
00,4c,00,45,00,25,00,5c,00,4d,00,79,00,20,00,44,00,6f,00,63,00,75,00,6d,00,\
65,00,6e,00,74,00,73,00,5c,00,4d,00,79,00,20,00,50,00,69,00,63,00,74,00,75,\
00,72,00,65,00,73,00,00,00
"Local Settings"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,\
49,00,4c,00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,\
00,74,00,74,00,69,00,6e,00,67,00,73,00,00,00
"Local AppData"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,\
49,00,4c,00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,\
00,74,00,74,00,69,00,6e,00,67,00,73,00,5c,00,41,00,70,00,70,00,6c,00,69,00,\
63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,00,00
"Cache"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,\
74,00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,6f,00,72,00,61,\
00,72,00,79,00,20,00,49,00,6e,00,74,00,65,00,72,00,6e,00,65,00,74,00,20,00,\
46,00,69,00,6c,00,65,00,73,00,00,00
"History"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00,5c,00,48,00,69,00,73,00,74,00,6f,00,72,00,79,00,00,00
问题:1. 如果存在 "History" 、"Local AppData"、"NetHood"、 "Personal"、"PrintHood"、"Recent"、"Cookies"、"My Pictures"、"Local AppData" 键值,就删除所在的整个键值。
2. 替换 "Programs" 为 "Common Programs" ,"Start Menu",为"Common Start Menu","Desktop" 为 "Common Desktop","Startup" 为 "Common Startup","AppData" 为 "Common AppData","Templates" 为 "Common Templates","Favorites" 为 "Common Favorites",其余的都删除。
3. 替换每一个键值下的 hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00(很有规律,这段16 进制代码之后的内容不能更改)为 hex(2):25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,50,00,52,00,\
4f,00,46,00,49,00,4c,00,45,00,25,00,可以先合并行再替换。
我的思路:是否可以先合并各个键值的行为一行,再替换更好?
要求:操作中保持 .reg 格式(即 unicode 文件格式)不变,hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\
4c,00,45,00,25,00 之后的内容不能动。
先谢谢!
-----------------------------------------------------------------------------------------------------
感谢 apang 等老师,我的问题圆满解决。将最终代码贴上,以供需要的参考:- Dim msg1, msg2, fso, ws, oArgs, iPath, tPath, sLoca, sPName, tPName
- msg1 = "HojoHE.exe -Sdefault -ID:\a -TE:\a\b -L00000409"
- msg2 = "HojoUE.exe -SC:\def.reg -TD:\sft.reg"
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set ws = CreateObject("WScript.Shell")
- Set oArgs = WScript.Arguments
-
- If oArgs.Count >= 4 Then
- If (Left(oArgs(0),2) = "-S") and (Left(oArgs(1),2) = "-I") and (Left(oArgs(2),2) = "-T") and (Left(oArgs(3),2) = "-L") Then
- iPath = Mid(oArgs(1), 3) & "\"
- tPath = Mid(oArgs(2), 3) & "\"
- sLoca = Mid(oArgs(3), 3)
- Call HojoHE()
- Else MsgBox "usage:" & vbLf & vbLf & msg1
- End If
- ElseIf oArgs.Count = 2 Then
- If Left(oArgs(0),2) = "-S" and (Left(oArgs(1),2) = "-T") Then
- sPName = Mid(oArgs(0), 3)
- tPName = Mid(oArgs(1), 3)
- Call ChangeRegFile()
- Else MsgBox "usage:" & vbLf & vbLf & msg2
- End If
- Else MsgBox "usage:" & vbLf & vbLf & msg1 & vbLf & "or" & vbLf & msg2
- End If
-
- Function HojoHE()
- On Error Resume Next
- Dim ar, i
- If Not fso.FolderExists(tPath) Then fso.CreateFolder tPath
- Select Case LCase(Mid(oArgs(0), 3))
- Case "default"
- fso.CopyFile iPath & "HIVEDEF.INF", tPath, true
- Call ProcessFile(tPath & "HIVEDEF.INF", "default")
- Case "software"
- ar = Array("HIVESFT","HIVECLS","HIVESXS","HIVCLS32","HIVSFT32","DMREG")
- For i = 0 to UBound(ar)
- fso.CopyFile iPath & ar(i) & ".INF", tPath, true
- Call ProcessFile(tPath & ar(i) & ".INF", "software")
- Next
- Case "setupreg.hiv"
- ar = Array("HIVESYS","INTL")
- For i = 0 to UBound(ar)
- fso.CopyFile iPath & ar(i) & ".INF", tPath, true
- Call ProcessFile(tPath & ar(i) & ".INF", "setup")
- Next
- Case Else MsgBox "The parameter isn't supported!" & vbLf & vbLf & "Must be 'default', or 'software', or 'setupreg.hiv'."
- WScript.Quit
- End Select
- End Function
-
- Function ChangeRegFile()
- Dim f, txt, re, m, s1, s2, s
- Set f = fso.OpenTextFile(sPName, 1, , -1)
- txt = f.ReadAll : f.Close
- Set re = New RegExp
- re.Pattern = "([\s\S]*?)(^"".+"" *=[\s\S]+?)(?=^"")"
- re.Global = true
- re.IgnoreCase = true
- re.MultiLine = true
- For Each m in re.Execute(txt & vbCrLf & """")
- s1 = m.SubMatches(0)
- s2 = ReReplace(m.SubMatches(1))
- If m.SubMatches(1) <> s2 Then
- s = s & s1 & s2
- Else s = s & s1
- End If
- Next
- s1 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
- re.Pattern = "(hex\(2\):)25,00,55,00,53,00,45,00,52,00,"
- s = re.Replace(s, "$1" & s1)
- re.Pattern = "WB-default\\Software"
- s = re.Replace(s, "WB-software")
- fso.OpenTextFile(tPName, 2, true, -1).Write s
- End Function
-
- Function ProcessFile(infFile, hivFile)
- Dim f, s, lgInst, yn
- Set f = fso.OpenTextFile(infFile, 1, false, GetFileFormat(infFile))
- s = f.ReadAll : f.Close
- s = ReplaceStr(s, "HKCU, *""", "HKLM,""WB-default\")
- s = ReplaceStr(s, "HKLM, *""SYSTEM\\CurrentControlSet", "HKLM,""WB-setup\ControlSet001")
- s = ReplaceStr(s, "HKLM, *""SYSTEM\\", "HKLM,""WB-setup\")
- s = ReplaceStr(s, "HKLM, *SYSTEM\\CurrentControlSet", "HKLM,WB-setup\ControlSet001")
- s = ReplaceStr(s, "HKLM, *SYSTEM\\", "HKLM,WB-setup\")
- s = ReplaceStr(s, "\\CryptSvc\\Security"",""Security"",0x00030003, *\\", "\CryptSvc\Security"",""Security"",0x00030003,00")
- s = ReplaceStr(s, "HKLM, *""SOFTWARE\\", "HKLM,""WB-software\")
- s = ReplaceStr(s, "HKLM, *SOFTWARE\\", "HKLM,WB-software\")
- s = ReplaceStr(s, "HKCR, *""", "HKLM,""WB-software\Classes\")
- s = ReplaceStr(s, "HKCR,\.", "HKLM,WB-software\Classes\.")
- If UCase(infFile) = UCase(tPath & "INTL.INF") Then
- s = ReplaceStr(s, "\[" & sLoca & "\]", "[DefaultInstall]")
- s = ReplaceStr(s, "CopyFile", ";CopyFile")
- lgInst = Split(ProssLocales(s), ",")
- s = ReplaceStr(s, "\[LG_INSTALL_(" & lgInst(0) & "|" & lgInst(1) & ")]", "[DefaultInstall]")
- ElseIf Left(s, 16) <> "[DefaultInstall]" Then
- s = "AddReg = AddReg.Upgrade" & vbCrLf & s
- s = "AddReg = AddReg.Fresh" & vbCrLf & s
- s = "AddReg = AddReg.RemoteBoot" & vbCrLf & s
- s = "AddReg = AddReg" & vbCrLf & s
- s = "[DefaultInstall]" & vbCrLf & s
- End If
- fso.OpenTextFile(infFile, 2, true, -1).Write s
- On Error Resume Next
- yn = ws.RegRead("HKEY_LOCAL_MACHINE\WB-" & hivFile & "\")
- If yn <> 0 Then
- infFile = fso.GetFile(infFile).ShortPath
- ws.Run "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 132 " & infFile, , true
- Else MsgBox "Error, the WB-" & hivFile & " not found and exit."
- End If
- End Function
-
- Function GetFileFormat(ByVal infFile)
- Dim Bin
- with CreateObject("Adodb.Stream")
- .Type = 1
- .Mode = 3
- .Open
- .Position = 0
- .Loadfromfile infFile
- Bin = .read(2)
- End with
- If AscB(MidB(Bin,1,1))=&HFF and AscB(MidB(Bin,2,1))=&HFE Then
- GetFileFormat = -1 ''unicode
- Else GetFileFormat = 0 ''ansi
- End If
- End Function
-
- Function ReplaceStr(ByVal s, pattern, s1)
- Dim re
- Set re = New RegExp
- re.Pattern = pattern
- re.Global = true
- re.IgnoreCase = true
- ReplaceStr = re.Replace(s, s1)
- End Function
-
- Function ProssLocales(ByVal s)
- Dim pattern1, pattern2, re, m
- pattern1 = "^ *\[Locales] *$"
- pattern2 = "^ *" & sLoca & " *=([^,]*,){2}([^,]*,[^,]*),.*$"
- Set re = New RegExp
- re.Pattern = pattern1 & "[\s\S]*?" & pattern2
- re.IgnoreCase = true
- re.MultiLine = true
- For Each m in re.Execute(s)
- ProssLocales = m.SubMatches(1)
- Next
- End Function
-
- Function ReReplace(str)
- Dim re, p
- p = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
- Set re = New RegExp
- re.Pattern = """(" & p & ")"""
- re.IgnoreCase = true
- ReReplace = re.Replace(str, """Common $1""")
- End Function
复制代码
作者: yuanyannian 时间: 2014-10-12 18:09
回复 1# yuanyannian
这题似乎有些麻烦?
作者: apang 时间: 2014-10-12 19:14
本帖最后由 apang 于 2014-10-12 23:59 编辑
不明白问题2:“其余的都删除”是什么意思- Set fso = CreateObject("Scripting.FileSystemObject")
- txt = fso.OpenTextFile("a.txt", 1, , -1).ReadAll
-
- p = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
- Set re = New RegExp
- re.Pattern = "([\s\S]*?)(^"".+"" *=[\s\S]+?)(?=^"")"
- re.Global = true
- re.MultiLine = true
- For Each m in re.Execute(txt)
- s1 = m.SubMatches(0)
- s2 = ReReplace(m.SubMatches(1))
- If m.SubMatches(1) <> s2 Then
- s = s & s1 & s2
- Else s = s & s1
- End If
- Next
-
- s1 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
- Set re = New RegExp
- re.Pattern = "(hex\(2\):)25,00,55,00,53,00,45,00,52,00,"
- re.Global = true
- re.IgnoreCase = true
- s = re.Replace(s, "$1" & s1)
-
- fso.OpenTextFile("b.txt", 2, true, -1).Write s
-
- Function ReReplace(str)
- Set re = New RegExp
- re.Pattern = """(" & p & ")"""
- re.IgnoreCase = true
- ReReplace = re.Replace(str, """Common $1""")
- End Function
复制代码
作者: yuanyannian 时间: 2014-10-12 20:02
回复 3# apang
意思是除了列出的那些,其它的,比如 “NetHood"、"Personal"、"PrintHood"、"Recent" 等键值都删除。或者说如何删除某个键值。
谢谢 apang 老师!
作者: apang 时间: 2014-10-12 20:15
回复 4# yuanyannian
你的意思是除了列出的Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites 这7个键值做替换外,其余的键值统统删除?
如果是这样,那问题1岂不多余?
作者: yuanyannian 时间: 2014-10-12 20:49
本帖最后由 yuanyannian 于 2014-10-12 20:51 编辑
回复 3# apang
好用,谢谢。
是的,是一个意思。
我将代码修改如下:- Set fso = CreateObject("Scripting.FileSystemObject")
- txt = fso.OpenTextFile("a.reg", 1, , -1).ReadAll
-
- p = "NetHood|Personal|PrintHood|Recent|SendTo|Cookies|My Pictures"
- p1 = p & "|Local Settings|Local AppData|Cache|History"
- Set re = New RegExp
- re.Pattern = "([\s\S]*?)""(" & p1 & ")""[\s\S]+?(?:"")"
- re.Global = true
- re.IgnoreCase = true
- For Each m in re.Execute(txt)
- str = str & """" & m.SubMatches(0)
- Next
- txt = Mid(str, 2)
-
- p2 = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
- Set re = New RegExp
- re.Pattern = """(" & p2 & ")"""
- re.Global = true
- re.IgnoreCase = true
- txt = re.Replace(txt, """Common $1""")
-
- w1 = "25,00,55,00,53,00,45,00,52,00," ''只将这些替换即可,因 ,\ 的位置不是固定的。
- w2 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
-
- Set re = New RegExp
- re.Pattern = "(hex\(2\):)" & w1
- re.Global = true
- re.IgnoreCase = true
- txt = re.Replace(txt, "$1" & w2)
-
- fso.OpenTextFile("b.reg", 2, true, -1).Write txt
复制代码
但有个问题:生成的 b.reg 中总有 Personal、SendTo、My Pictures 去除不了。
请 apang 老师给看一下。
作者: apang 时间: 2014-10-12 22:11
本帖最后由 apang 于 2014-10-12 22:24 编辑
保存为test.bat- @set @n=0;// & cscript -nologo -e:jscript "%~0" & pause & exit
-
- fso = new ActiveXObject('Scripting.FileSystemObject');
- txt = fso.OpenTextFile('a.txt', 1, false, -1).ReadAll();
- re = /([\s\S]*?)(^".+" *=[\s\S]+?)(?=^")/mg;
- s = '';
- r =/^"(Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites)"/i;
- while ((ar = re.exec(txt)) !=null) {
- if (r.test(ar[2])) {
- s += ar[1] + ar[2].replace(r, '"Common $1"');
- } else s += ar[1];
- }
-
- s1='25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,50,00,52,00,\\';
- s2='4f,00,46,00,49,00,4c,00,45,00,25,00';
- p1='25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,\\\\';
- p2='4c,00,45,00,25,00';
- re=new RegExp('(hex\\(2\\):)' + p1 + '( *\\r?\\n *)' + p2, 'ig');
- s = s.replace(re, '$1' + s1 + '$2' + s2);
-
- fso.OpenTextFile('b.txt', 2, true, -1).Write(s)
复制代码
作者: apang 时间: 2014-10-13 00:01
回复 6# yuanyannian
好吧,3楼修改下,应该没问题了
作者: CrLf 时间: 2014-10-13 00:03
这么大坨的描述,看了真头疼
作者: yuanyannian 时间: 2014-10-13 16:40
回复 8# apang
是的,非常好用。
另外想请求 appang 老师:之前一直请教的处理 Unicode 格式文件的脚本已经在使用中,加之这次请教的脚本,独立使用都没有问题。但我想将两者合并起来,怎么也不行,所以麻烦 apang 老师给费费心,我将两个脚本以及需要处理的相关文件贴上附件,请老师帮忙,非常感谢。
1. 脚本
[attach]7778[/attach]
2. 需要处理的文件(文件过大,给出下载地址)
http://pan.baidu.com/s/1qWoHOD2
作者: apang 时间: 2014-10-13 21:41
回复 10# yuanyannian
需要判断参数个数,蛋疼,相当蛋疼,恕不能帮忙
作者: apang 时间: 2014-10-13 21:53
3#代码还是有点问题,如果 Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites 这7个键值中的任意一个位于reg文件的最后面,将会匹配不到而导致结果错误- Set fso = CreateObject("Scripting.FileSystemObject")
- txt = fso.OpenTextFile("a.txt", 1, , -1).ReadAll
-
- p = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
- Set re = New RegExp
- re.Pattern = "([\s\S]*?)(^"".+"" *=[\s\S]+?)(?=^"")"
- re.Global = true
- re.MultiLine = true
- For Each m in re.Execute(txt & vbCrLf & """")
- s1 = m.SubMatches(0)
- s2 = ReReplace(m.SubMatches(1))
- If m.SubMatches(1) <> s2 Then
- s = s & s1 & s2
- Else s = s & s1
- End If
- Next
-
- s1 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
- Set re = New RegExp
- re.Pattern = "(hex\(2\):)25,00,55,00,53,00,45,00,52,00,"
- re.Global = true
- re.IgnoreCase = true
- s = re.Replace(s, "$1" & s1)
-
- fso.OpenTextFile("b.txt", 2, true, -1).Write Left(s, Len(s)-2)
-
- Function ReReplace(str)
- Set re = New RegExp
- re.Pattern = """(" & p & ")"""
- re.IgnoreCase = true
- ReReplace = re.Replace(str, """Common $1""")
- End Function
复制代码
作者: yuanyannian 时间: 2014-10-14 06:48
本帖最后由 yuanyannian 于 2014-10-14 06:53 编辑
回复 11# apang
理解,这已经十分感谢了!如果没有老师的无私相助,我根本无法写出来 vbs。
作者: yuanyannian 时间: 2014-10-14 06:51
回复 12# apang
查看了所有语言的 HKEY_LOCAL_MACHINE\pe-def\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders,几乎是一样的排列。
作者: yuanyannian 时间: 2014-10-15 19:39
回复 12# apang
apang 老师还真不愿帮忙啊?有求了!!!
作者: apang 时间: 2014-10-16 01:13
本帖最后由 apang 于 2014-10-18 00:14 编辑
回复 15# yuanyannian
太长太乱,看得头都大,如果还有问题,请自行修改- Dim msg1, msg2, fso, ws, oArgs, iPath, tPath, sLoca, sPName, tPName
- msg1 = "HojoHE.exe -Sdefault -ID:\a -TE:\a\b -L00000409"
- msg2 = "HojoUE.exe -SC:\def.reg -TD:\sft.reg"
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set ws = CreateObject("WScript.Shell")
- Set oArgs = WScript.Arguments
-
- If oArgs.Count >= 4 Then
- If (Left(oArgs(0),2) = "-S") and (Left(oArgs(1),2) = "-I") and _
- (Left(oArgs(2),2) = "-T") and (Left(oArgs(3),2) = "-L") Then
- iPath = Mid(oArgs(1), 3) & "\"
- tPath = Mid(oArgs(2), 3) & "\"
- sLoca = Mid(oArgs(3), 3)
- Call HojoHE()
- Else
- MsgBox "usage:" & vbLf & vbLf & msg1
- End If
- ElseIf oArgs.Count = 2 Then
- If Left(oArgs(0),2) = "-S" and (Left(oArgs(1),2) = "-T") Then
- sPName = Mid(oArgs(0), 3)
- tPName = Mid(oArgs(1), 3)
- Call ChangeRegFile()
- Else
- MsgBox "usage:" & vbLf & vbLf & msg2
- End If
- Else
- MsgBox "usage:" & vbLf & vbLf & msg1 & vbLf & "or" & vbLf & msg2
- End If
-
- Function HojoHE()
- On Error Resume Next
- Dim ar, i
- If Not fso.FolderExists(tPath) Then fso.CreateFolder tPath
- Select Case LCase(Mid(oArgs(0), 3))
- Case "default"
- fso.CopyFile iPath & "HIVEDEF.INF", tPath, true
- Call ProcessFile(tPath & "HIVEDEF.INF", "default")
- Case "software"
- ar = Array("HIVESFT","HIVECLS","HIVESXS","HIVCLS32","HIVSFT32","DMREG")
- For i = 0 to UBound(ar)
- fso.CopyFile iPath & ar(i) & ".INF", tPath, true
- Call ProcessFile(tPath & ar(i) & ".INF", "software")
- Next
- Case "setupreg.hiv"
- ar = Array("HIVESYS","INTL")
- For i = 0 to UBound(ar)
- fso.CopyFile iPath & ar(i) & ".INF", tPath, true
- Call ProcessFile(tPath & ar(i) & ".INF", "setupreg.hiv")
- Next
- Case Else
- MsgBox "The parameter isn't supported!" & vbLf & vbLf & _
- "Must be 'default', or 'software', or 'setupreg.hiv'."
- WScript.Quit
- End Select
- End Function
-
- Function ChangeRegFile()
- Dim f, txt, re, m, s1, s2, s
- Set f = fso.OpenTextFile(sPName, 1, , -1)
- txt = f.ReadAll : f.Close
- Set re = New RegExp
- re.Pattern = "([\s\S]*?)(^"".+"" *=[\s\S]+?)(?=^"")"
- re.Global = true
- re.IgnoreCase = true
- re.MultiLine = true
- For Each m in re.Execute(txt & vbCrLf & """")
- s1 = m.SubMatches(0)
- s2 = ReReplace(m.SubMatches(1))
- If m.SubMatches(1) <> s2 Then
- s = s & s1 & s2
- Else s = s & s1
- End If
- Next
- s1 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
- re.Pattern = "(hex\(2\):)25,00,55,00,53,00,45,00,52,00,"
- s = re.Replace(s, "$1" & s1)
- re.Pattern = "pe-def\\Software"
- s = re.Replace(s, "pe-soft")
- fso.OpenTextFile(tPName, 2, true, -1).Write s
- End Function
-
- Function ProcessFile(infFile, hivFile)
- Dim f, s, lgInst
- Set f = fso.OpenTextFile(infFile, 1, false, GetFileFormat(infFile))
- s = f.ReadAll : f.Close
- s = ReplaceStr(s, "HKCU, *""", "HKLM,""WB-default\")
- s = ReplaceStr(s, "HKLM, *""SYSTEM\\CurrentControlSet", "HKLM,""WB-setup\ControlSet001")
- s = ReplaceStr(s, "HKLM, *""SYSTEM\\", "HKLM,""WB-setup\")
- s = ReplaceStr(s, "HKLM, *SYSTEM\\CurrentControlSet", "HKLM,WB-setup\ControlSet001")
- s = ReplaceStr(s, "HKLM, *SYSTEM\\", "HKLM,WB-setup\")
- s = ReplaceStr(s, "\\CryptSvc\\Security"",""Security"",0x00030003, *\\", "\CryptSvc\Security"",""Security"",0x00030003,00")
- s = ReplaceStr(s, "HKLM, *""SOFTWARE\\", "HKLM,""WB-software\")
- s = ReplaceStr(s, "HKLM, *SOFTWARE\\", "HKLM,WB-software\")
- s = ReplaceStr(s, "HKCR, *""", "HKLM,""WB-software\Classes\")
- s = ReplaceStr(s, "HKCR,\.", "HKLM,WB-software\Classes\.")
- If UCase(infFile) = UCase(tPath & "INTL.INF") Then
- s = ReplaceStr(s, "\[" & sLoca & "\]", "[DefaultInstall]")
- s = ReplaceStr(s, "CopyFile", ";CopyFile")
- lgInst = Split(ProssLocales(s), ",")
- s = ReplaceStr(s, "\[LG_INSTALL_(" & lgInst(0) & "|" & lgInst(1) & ")]", "[DefaultInstall]")
- ElseIf Left(s, 16) <> "[DefaultInstall]" Then
- s = "AddReg = AddReg.Upgrade" & vbCrLf & s
- s = "AddReg = AddReg.Fresh" & vbCrLf & s
- s = "AddReg = AddReg.RemoteBoot" & vbCrLf & s
- s = "AddReg = AddReg" & vbCrLf & s
- s = "[DefaultInstall]" & vbCrLf & s
- End If
-
- fso.OpenTextFile(infFile, 2, true, -1).Write s
- ''ws.RegRead "HKEY_LOCAL_MACHINE\WB-" & hivFile & "\"
- If Err.Number = 0 Then
- Err.Clear
- infFile = fso.GetFile(infFile).ShortPath
- ws.Run "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 132 " & infFile, , true
- Else
- MsgBox "Error, the WB-" & hivFile & " not found and exit."
- End If
- End Function
-
- Function GetFileFormat(ByVal infFile)
- Dim Bin
- with CreateObject("Adodb.Stream")
- .Type = 1
- .Mode = 3
- .Open
- .Position = 0
- .Loadfromfile infFile
- Bin = .read(2)
- End with
- If AscB(MidB(Bin,1,1))=&HFF and AscB(MidB(Bin,2,1))=&HFE Then
- GetFileFormat = -1 ''unicode
- Else GetFileFormat = 0 ''ansi
- End If
- End Function
-
- Function ReplaceStr(ByVal s, pattern, s1)
- Dim re
- Set re = New RegExp
- re.Pattern = pattern
- re.Global = true
- re.IgnoreCase = true
- ReplaceStr = re.Replace(s, s1)
- End Function
-
- Function ProssLocales(ByVal s)
- Dim pattern1, pattern2, re, m
- pattern1 = "^ *\[Locales] *$"
- pattern2 = "^ *" & sLoca & " *=([^,]*,){2}([^,]*,[^,]*),.*$"
- Set re = New RegExp
- re.Pattern = pattern1 & "[\s\S]*?" & pattern2
- re.IgnoreCase = true
- re.MultiLine = true
- For Each m in re.Execute(s)
- ProssLocales = m.SubMatches(1)
- Next
- End Function
-
- Function ReReplace(str)
- Dim re, p
- p = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
- Set re = New RegExp
- re.Pattern = """(" & p & ")"""
- re.IgnoreCase = true
- ReReplace = re.Replace(str, """Common $1""")
- End Function
复制代码
作者: yuanyannian 时间: 2014-10-16 17:36
非常非常感谢!!!
作者: CrLf 时间: 2014-10-16 18:01
回复 17# yuanyannian
那结帖后给胖大大加个分呗
作者: yuanyannian 时间: 2014-10-16 19:27
回复 18# CrLf
当然应该,可如何加呢?
作者: yuanyannian 时间: 2014-10-17 19:28
本帖最后由 yuanyannian 于 2014-10-17 19:34 编辑
回复 16# apang
1. 无法读取 hiveFile,导致 .INF 文件不能注册。
2. If Not infFile = tPath & "INTL.INF" Then 这行似乎无效。
再次感谢 apang 老师 !!!
作者: apang 时间: 2014-10-18 00:23
回复 20# yuanyannian
1 我的win7无法测试注册是否成功,先注释掉第110行试试
2 少了一个参数,已修改
作者: yuanyannian 时间: 2014-10-18 07:04
回复 21# apang
谢谢!
可以了,把 110 到 113 行换为:- On Error Resume Next
- yn = ws.RegRead("HKEY_LOCAL_MACHINE\WB-" & hivFile & "\")
- If yn <> 0 Then
- infFile = fso.GetFile(infFile).ShortPath
复制代码
把 52 行换为:- Call ProcessFile(tPath & ar(i) & ".INF", "setup")
复制代码
应该没问题了,待进一步测试一下。
另外请教,在 117 行后面,即 MsgBox "Error, the WB-" & hivFile & " not found and exit.",不用": WScript.Quit" 可以退出吗?
作者: apang 时间: 2014-10-19 11:43
回复 22# yuanyannian
在 117 行后面,即 MsgBox "Error, the WB-" & hivFile & " not found and exit.",不用": WScript.Quit" 可以退出吗?
你自己试下呀
加上WScript.Quit会中途强行退出,不会处理其它文件(如果有多个文件需要处理的话),这个根据需要吧。
作者: yuanyannian 时间: 2014-10-19 14:02
回复 23# apang
非常感谢!可以结贴了。
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |