Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.3 KiB

  1. <?XML version="1.0" ?>
  2. <package>
  3. <comment>
  4. <![CDATA[
  5. VBSCRIPT parse the unattend.temp file to execute a
  6. Perl-like regexp subst pattern
  7. $line=~/\$\{(\w+)\}/$ENV{$1}/g
  8. (see parsesys.pl on BVT machine)
  9. ]]>
  10. </comment>
  11. <job error="false" debug="false" logo="false">
  12. <resource id="environment">PROCESS</resource>
  13. <resource id="path">%BOOTTESTDRIVE%\TOOLS</resource>
  14. <resource id="ifile">unattend.temp</resource>
  15. <resource id="ofile">unattend.txt</resource>
  16. <resource id="sample"><![CDATA[ProductID="${P_roductID}"]]></resource>
  17. <resource id="pattern"><![CDATA[\$\{(\w+)\}]]></resource>
  18. <script language="VBScript">
  19. <![CDATA[
  20. Option Explicit
  21. '' One of three Tristate values used to indicate
  22. '' the format of the opened file.
  23. Const TristateFalse = 0 '' Opens the file as ASCII.
  24. Const TristateTrue = - 1 '' Opens the file as Unicode.
  25. Const TristateUseDefault = - 2 '' Opens the file using the system default.
  26. Const QUOTE = """"
  27. Const cDebug = False
  28. Const ForReading = 1
  29. Const ForWriting = 2
  30. Const ForAppending = 8
  31. Dim spSample, opRexpVa, opRexpUp, aspEnv, opReplace, spGenPat
  32. Dim opShell, opFileSys, dpEnv, spText, spEnv
  33. Dim spPath, spIName, spOName, siIName, siOName, siPath
  34. Dim spExpdIPath, spExpdOPath, opStearm, opIFile, opOFile
  35. Set opFileSys = CreateObject("Scripting.FilesystemObject")
  36. Set opShell = WScript.CreateObject("WScript.Shell")
  37. Set dpEnv = CreateObject("Scripting.Dictionary")
  38. spPath = GetResource("path")
  39. spIName = GetResource("ifile")
  40. spOName = GetResource("ofile")
  41. siPath = WScript.Arguments.Named("path")
  42. siIName = WScript.Arguments.Named("in")
  43. siOName = WScript.Arguments.Named("out")
  44. If siPath <> "" Then
  45. spPath = siPath
  46. End If
  47. If siIName <> "" Then
  48. spIName = siIName
  49. End If
  50. If siOName <> "" Then
  51. spOName = siOName
  52. End If
  53. For Each spEnv In opShell.Environment(CStr(GetResource("environment")))
  54. aspEnv = Split(spEnv,"=")
  55. If 1 = UBound(aspEnv) Then
  56. dpEnv.add UCase(aspEnv(0)), aspEnv(1)
  57. End If
  58. Next
  59. spGenPat = CStr(GetResource("pattern"))
  60. spExpdIPath = opShell.ExpandEnvironmentStrings(_
  61. spPath & "\" & spIName)
  62. spExpdOPath = opShell.ExpandEnvironmentStrings(_
  63. spPath & "\" & spOName)
  64. spIName = opFileSys.GetFileName(opFileSys.GetAbsolutePathName(spExpdIPath))
  65. spOName = opFileSys.GetFileName(opFileSys.GetAbsolutePathName(spExpdOPath))
  66. Set opIFile = opFileSys.GetFile(spExpdIPath)
  67. Set opOFile = opFileSys.CreateTextFile(spExpdOPath, True)
  68. set opStearm = opIFile.OpenAsTextStream(ForReading, TristateUseDefault)
  69. Do while opStearm.AtEndOfStream <> true
  70. spSample = opStearm.ReadLine
  71. Set opRexpVa = New RegExp
  72. With opRexpVa
  73. .Pattern = spGenPat
  74. .Global = True
  75. .IgnoreCase = True
  76. .MultiLine = True
  77. End With
  78. Do While True = opRexpVa.Test(spSample)
  79. Set opRexpUp = New RegExp
  80. With opRexpUp
  81. .Global = True
  82. .IgnoreCase = True
  83. .Pattern = spGenPat
  84. End with
  85. For Each opReplace in opRexpVa.Execute(spSample)
  86. spEnv = opRexpUp.Replace(opReplace.Value, "$1")
  87. opRexpUp.Pattern = Replace(spGenPat, "(\w+)", spEnv)
  88. If cDebug Then
  89. WSCript.echo "opRexpVa.Pattern=", QUOTE & opRexpVa.Pattern & QUOTE
  90. WScript.echo "opRexpUp.Pattern=", opRexpUp.Pattern
  91. WScript.echo "spSample=", spSample
  92. End if
  93. spSample = opRexpUp.Replace(spSample, dpEnv(UCase(spEnv)))
  94. If cDebug Then
  95. WScript.echo "spSample=", spSample & VBNEWLINE
  96. End If
  97. Next
  98. Set opRexpUp = Nothing
  99. Loop
  100. Set opRexpVa = Nothing
  101. opOFile.Write spSample & VBNEWLINE
  102. Loop
  103. Set opFileSys = Nothing
  104. set opshell = Nothing
  105. Set dpEnv = Nothing
  106. ]]>
  107. </script>
  108. </job>
  109. </package>