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

回复 15# yuanyannian


    太长太乱,看得头都大,如果还有问题,请自行修改
  1. Dim msg1, msg2, fso, ws, oArgs, iPath, tPath, sLoca, sPName, tPName
  2. msg1 = "HojoHE.exe -Sdefault -ID:\a -TE:\a\b -L00000409"
  3. msg2 = "HojoUE.exe -SC:\def.reg -TD:\sft.reg"
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. Set ws = CreateObject("WScript.Shell")
  6. Set oArgs = WScript.Arguments
  7. If oArgs.Count >= 4 Then
  8.     If (Left(oArgs(0),2) = "-S") and (Left(oArgs(1),2) = "-I") and _
  9.             (Left(oArgs(2),2) = "-T") and (Left(oArgs(3),2) = "-L") Then
  10.         iPath = Mid(oArgs(1), 3) & "\"
  11.         tPath = Mid(oArgs(2), 3) & "\"
  12.         sLoca = Mid(oArgs(3), 3)
  13.         Call HojoHE()
  14.     Else
  15.         MsgBox "usage:" & vbLf & vbLf & msg1
  16.     End If
  17. ElseIf oArgs.Count = 2 Then
  18.     If Left(oArgs(0),2) = "-S" and (Left(oArgs(1),2) = "-T") Then
  19.         sPName = Mid(oArgs(0), 3)
  20.         tPName = Mid(oArgs(1), 3)
  21.         Call ChangeRegFile()
  22.     Else
  23.         MsgBox "usage:" & vbLf & vbLf & msg2
  24.     End If
  25. Else
  26.     MsgBox "usage:" & vbLf & vbLf & msg1 & vbLf & "or" & vbLf & msg2
  27. End If
  28. Function HojoHE()
  29.     On Error Resume Next
  30.     Dim ar, i
  31.     If Not fso.FolderExists(tPath) Then fso.CreateFolder tPath
  32.     Select Case LCase(Mid(oArgs(0), 3))
  33.         Case "default"
  34.             fso.CopyFile iPath & "HIVEDEF.INF", tPath, true
  35.             Call ProcessFile(tPath & "HIVEDEF.INF", "default")
  36.         Case "software"
  37.             ar = Array("HIVESFT","HIVECLS","HIVESXS","HIVCLS32","HIVSFT32","DMREG")
  38.             For i = 0 to UBound(ar)
  39.                 fso.CopyFile iPath & ar(i) & ".INF", tPath, true
  40.                 Call ProcessFile(tPath & ar(i) & ".INF", "software")            
  41.             Next
  42.         Case "setupreg.hiv"
  43.             ar = Array("HIVESYS","INTL")
  44.             For i = 0 to UBound(ar)
  45.                 fso.CopyFile iPath & ar(i) & ".INF", tPath, true
  46.                 Call ProcessFile(tPath & ar(i) & ".INF", "setupreg.hiv")            
  47.             Next
  48.         Case Else
  49.             MsgBox "The parameter isn't supported!" & vbLf & vbLf & _
  50.                    "Must be 'default', or 'software', or 'setupreg.hiv'."
  51.             WScript.Quit
  52.     End Select
  53. End Function
  54. Function ChangeRegFile()
  55.     Dim f, txt, re, m, s1, s2, s
  56.     Set f = fso.OpenTextFile(sPName, 1, , -1)
  57.     txt = f.ReadAll : f.Close
  58.     Set re = New RegExp
  59.     re.Pattern = "([\s\S]*?)(^"".+"" *=[\s\S]+?)(?=^"")"
  60.     re.Global = true
  61.     re.IgnoreCase = true
  62.     re.MultiLine = true
  63.     For Each m in re.Execute(txt & vbCrLf & """")
  64.         s1 = m.SubMatches(0)
  65.         s2 = ReReplace(m.SubMatches(1))
  66.         If m.SubMatches(1) <> s2 Then
  67.             s = s & s1 & s2
  68.         Else s = s & s1
  69.         End If
  70.     Next
  71.     s1 = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,"
  72.     re.Pattern = "(hex\(2\):)25,00,55,00,53,00,45,00,52,00,"
  73.     s = re.Replace(s, "$1" & s1)
  74.     re.Pattern = "pe-def\\Software"
  75.     s = re.Replace(s, "pe-soft")
  76.     fso.OpenTextFile(tPName, 2, true, -1).Write s
  77. End Function
  78. Function ProcessFile(infFile, hivFile)
  79.     Dim f, s, lgInst
  80.     Set f = fso.OpenTextFile(infFile, 1, false, GetFileFormat(infFile))
  81.     s = f.ReadAll : f.Close
  82.     s = ReplaceStr(s, "HKCU, *""", "HKLM,""WB-default\")
  83.     s = ReplaceStr(s, "HKLM, *""SYSTEM\\CurrentControlSet", "HKLM,""WB-setup\ControlSet001")
  84.     s = ReplaceStr(s, "HKLM, *""SYSTEM\\", "HKLM,""WB-setup\")
  85.     s = ReplaceStr(s, "HKLM, *SYSTEM\\CurrentControlSet", "HKLM,WB-setup\ControlSet001")
  86.     s = ReplaceStr(s, "HKLM, *SYSTEM\\", "HKLM,WB-setup\")
  87.     s = ReplaceStr(s, "\\CryptSvc\\Security"",""Security"",0x00030003, *\\", "\CryptSvc\Security"",""Security"",0x00030003,00")
  88.     s = ReplaceStr(s, "HKLM, *""SOFTWARE\\", "HKLM,""WB-software\")
  89.     s = ReplaceStr(s, "HKLM, *SOFTWARE\\", "HKLM,WB-software\")
  90.     s = ReplaceStr(s, "HKCR, *""", "HKLM,""WB-software\Classes\")
  91.     s = ReplaceStr(s, "HKCR,\.", "HKLM,WB-software\Classes\.")
  92.     If UCase(infFile) = UCase(tPath & "INTL.INF") Then
  93.         s = ReplaceStr(s, "\[" & sLoca & "\]", "[DefaultInstall]")
  94.         s = ReplaceStr(s, "CopyFile", ";CopyFile")
  95.         lgInst = Split(ProssLocales(s), ",")
  96.         s = ReplaceStr(s, "\[LG_INSTALL_(" & lgInst(0) & "|" & lgInst(1) & ")]", "[DefaultInstall]")
  97.     ElseIf Left(s, 16) <> "[DefaultInstall]" Then
  98.         s = "AddReg = AddReg.Upgrade" & vbCrLf & s
  99.         s = "AddReg = AddReg.Fresh" & vbCrLf & s
  100.         s = "AddReg = AddReg.RemoteBoot" & vbCrLf & s
  101.         s = "AddReg = AddReg" & vbCrLf & s
  102.         s = "[DefaultInstall]" & vbCrLf & s
  103.     End If
  104.     fso.OpenTextFile(infFile, 2, true, -1).Write s
  105.     ''ws.RegRead "HKEY_LOCAL_MACHINE\WB-" & hivFile & "\"
  106.     If Err.Number = 0 Then
  107.         Err.Clear
  108.         infFile = fso.GetFile(infFile).ShortPath
  109.         ws.Run "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 132 " & infFile, , true
  110.     Else
  111.         MsgBox "Error, the WB-" & hivFile & " not found and exit."
  112.     End If
  113. End Function
  114. Function GetFileFormat(ByVal infFile)
  115.     Dim Bin
  116.     with CreateObject("Adodb.Stream")
  117.         .Type = 1
  118.         .Mode = 3
  119.         .Open
  120.         .Position = 0
  121.         .Loadfromfile infFile
  122.         Bin = .read(2)
  123.     End with
  124.     If AscB(MidB(Bin,1,1))=&HFF and AscB(MidB(Bin,2,1))=&HFE Then
  125.         GetFileFormat = -1   ''unicode
  126.     Else GetFileFormat = 0   ''ansi
  127.     End If
  128. End Function
  129. Function ReplaceStr(ByVal s, pattern, s1)
  130.     Dim re
  131.     Set re = New RegExp
  132.     re.Pattern = pattern
  133.     re.Global = true
  134.     re.IgnoreCase = true
  135.     ReplaceStr = re.Replace(s, s1)
  136. End Function
  137. Function ProssLocales(ByVal s)
  138.     Dim pattern1, pattern2, re, m
  139.     pattern1 = "^ *\[Locales] *$"
  140.     pattern2 = "^ *" & sLoca & " *=([^,]*,){2}([^,]*,[^,]*),.*$"
  141.     Set re = New RegExp
  142.     re.Pattern = pattern1 & "[\s\S]*?" & pattern2
  143.     re.IgnoreCase = true
  144.     re.MultiLine = true
  145.     For Each m in re.Execute(s)
  146.         ProssLocales = m.SubMatches(1)
  147.     Next
  148. End Function
  149. Function ReReplace(str)
  150.     Dim re, p
  151.     p = "Programs|Start Menu|Desktop|Startup|AppData|Templates|Favorites"
  152.     Set re = New RegExp
  153.     re.Pattern = """(" & p & ")"""
  154.     re.IgnoreCase = true
  155.     ReReplace = re.Replace(str, """Common $1""")
  156. End Function
复制代码
1

评分人数

    • yuanyannian: 感谢 apang 老师的无私相助。技术 + 1

TOP

非常非常感谢!!!
76626yyn

TOP

回复 17# yuanyannian


    那结帖后给胖大大加个分呗

TOP

回复 18# CrLf

当然应该,可如何加呢?
76626yyn

TOP

本帖最后由 yuanyannian 于 2014-10-17 19:34 编辑

回复 16# apang

1. 无法读取 hiveFile,导致 .INF 文件不能注册。
2. If Not infFile = tPath & "INTL.INF" Then 这行似乎无效。

再次感谢 apang 老师 !!!
76626yyn

TOP

回复 20# yuanyannian


1 我的win7无法测试注册是否成功,先注释掉第110行试试
2 少了一个参数,已修改

TOP

回复 21# apang
谢谢!
可以了,把 110 到 113 行换为:
  1.     On Error Resume Next
  2.     yn = ws.RegRead("HKEY_LOCAL_MACHINE\WB-" & hivFile & "\")
  3.     If yn <> 0 Then
  4.         infFile = fso.GetFile(infFile).ShortPath
复制代码
把 52 行换为:
  1. Call ProcessFile(tPath & ar(i) & ".INF", "setup")
复制代码
应该没问题了,待进一步测试一下。

另外请教,在 117 行后面,即 MsgBox "Error, the WB-" & hivFile & " not found and exit.",不用": WScript.Quit" 可以退出吗?
76626yyn

TOP

回复 22# yuanyannian


   
在 117 行后面,即 MsgBox "Error, the WB-" & hivFile & " not found and exit.",不用": WScript.Quit" 可以退出吗?


你自己试下呀
加上WScript.Quit会中途强行退出,不会处理其它文件(如果有多个文件需要处理的话),这个根据需要吧。

TOP

回复 23# apang

非常感谢!可以结贴了。
76626yyn

TOP

返回列表