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.

264 lines
8.2 KiB

  1. '
  2. ' Script to update OS install MSI package
  3. ' Syntax: cscript OsPack.vbs package_path platform build_number language_number
  4. '
  5. '
  6. Sub Usage
  7. Wscript.echo "Script to update OS install MSI package. Syntax:"
  8. Wscript.echo " cscript OsPack.vbs package_path platform build_number language_number"
  9. Wscript.echo " package_path - path to package to update. requires read/write access"
  10. Wscript.echo " platform - must be either 'Alpha' or 'Intel'"
  11. Wscript.echo " build_number - 4 digit build number of the current build, i.e 1877"
  12. Wscript.echo " language_number - Language Id of the desired language, i.e. 1033 = US English, 0=Neutral"
  13. Wscript.Quit -1
  14. End Sub
  15. ' takes a string of the form 0x409 and converts it to an int
  16. Function IntFromHex( szInHexString )
  17. szHexString = szInHexString
  18. IntFromHex = 0
  19. multiplier = 1
  20. While( Ucase(Right( szHexString, 1 )) <> "X" )
  21. Ch = Ucase(Right( szHexString, 1 ))
  22. Select Case Ch
  23. Case "A" Ch = 10
  24. Case "B" Ch = 11
  25. Case "C" Ch = 12
  26. Case "D" Ch = 13
  27. Case "E" Ch = 14
  28. Case "F" Ch = 15
  29. End Select
  30. IntFromHex = IntFromHex + multiplier * Ch
  31. multiplier = multiplier * 16
  32. szHexString = Left( szHexString, Len (szHexString) -1 )
  33. Wend
  34. Exit Function
  35. End Function
  36. '
  37. ' Uses uuidgen.exe to generate a GUID, then formats it to be
  38. ' a MSI acceptable string guid
  39. '
  40. ' This makes use of a temporary file %temp%\MakeTempGUID.txt
  41. '
  42. Function MakeGuid()
  43. Dim WSHShell, FileSystem, File, ret, TempFileName
  44. Set WSHShell = CreateObject("WScript.Shell")
  45. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  46. TempFileName = WshShell.ExpandEnvironmentStrings( "%temp%\MakeTempGUID.txt" )
  47. if FileSystem.fileExists ( TempFileName ) Then
  48. FileSystem.DeleteFile TempFileName
  49. End If
  50. ret = WSHShell.Run("uuidgen -o" & TempFileName, 2, True)
  51. if FileSystem.fileExists ( TempFileName ) Then
  52. Set File = FileSystem.OpenTextFile(TempFileName, 1, True)
  53. MakeGuid = "{" & UCase(File.ReadLine) & "}"
  54. File.Close
  55. FileSystem.DeleteFile TempFileName
  56. Wscript.echo " Generated GUID: " & MakeGuid
  57. Else
  58. MakeGuid = "{00000000-0000-0000-0000-000000000000}"
  59. Wscript.echo " ERROR: Failed to generate GUID"
  60. End If
  61. Exit Function
  62. End Function
  63. '
  64. ' Updates the OS install MSI package using the following paramaters
  65. ' szPackage - path to package to update. requires read/write access
  66. ' szPlatform - must be either "Alpha" or "Intel"
  67. ' dwBuildNumber - 4 digit build number of the current build, i.e 1877
  68. ' dwLanguage - Language Id of the desired language, i.e. 1033 = US English, 0=Neutral
  69. '
  70. Function UpdateOsPackage(szPackage, szPlatform, dwBuildNumber, dwLanguage )
  71. Dim WSHShell, Installer, Database, SummaryInfo, Record, View, SQL
  72. Wscript.echo "Updating OS install package: " & szPackage
  73. Wscript.echo " For: " & szPlatform
  74. Wscript.echo " Build: " & dwBuildNumber
  75. Wscript.echo " Lang: " & dwLanguage
  76. UpdateOsPackage = 0
  77. On Error Resume Next
  78. 'Create the MSI API object
  79. Set Installer = CreateObject("WindowsInstaller.Installer")
  80. If Err <> 0 Then
  81. Set Installer = CreateObject("WindowsInstaller.Application")
  82. End If
  83. If Err <> 0 Then
  84. Set Installer = CreateObject("Msi.ApiAutomation")
  85. End if
  86. If Err <> 0 Then
  87. Wscript.echo "ERROR: Error creating Installer object"
  88. UpdateOsPackage = -1
  89. End if
  90. 'Create the WSH shell object
  91. Set WSHShell = CreateObject("WScript.Shell")
  92. If Err <> 0 Then
  93. Wscript.echo "ERROR: Error creating WSHShell object"
  94. UpdateOsPackage = -1
  95. End if
  96. 'Open the package
  97. Set Database = Installer.OpenDatabase(szPackage, 1)
  98. If Err <> 0 Then
  99. Wscript.echo "ERROR: Error opening database"
  100. UpdateOsPackage = -1
  101. End if
  102. Wscript.echo " Database opened for update"
  103. 'Generate and set a new package code
  104. Set SummaryInfo = Database.SummaryInformation( 3 )
  105. If Err <> 0 Then
  106. Wscript.echo "ERROR: Creating Summary Info Object"
  107. UpdateOsPackage = -1
  108. End if
  109. SummaryInfo.Property(9) = MakeGuid()
  110. If Err <> 0 Then
  111. Wscript.echo "ERROR: Error setting package code"
  112. UpdateOsPackage = -1
  113. End if
  114. Wscript.echo " Updated package Code"
  115. 'Update Platform and Language list
  116. SummaryInfo.Property(7) = szPlatform & ";" & dwLanguage
  117. If Err <> 0 Then
  118. Wscript.echo "ERROR: Error setting platform and langusge list"
  119. UpdateOsPackage = -1
  120. End if
  121. Wscript.echo " Updated Language and platform list to: " & szPlatform & ";" & dwLanguage
  122. SummaryInfo.Persist
  123. If Err <> 0 Then
  124. Wscript.echo "ERROR: Error persisting summary info"
  125. UpdateOsPackage = -1
  126. End if
  127. Wscript.echo " persisted summary stream"
  128. 'Generate and set a new product code
  129. SQL = "UPDATE Property SET Property.Value = '" & MakeGuid() & "' WHERE Property.Property= 'ProductCode'"
  130. set View = Database.OpenView( SQL )
  131. If Err <> 0 Then
  132. Wscript.echo "ERROR: Error opening view: " & SQL
  133. UpdateOsPackage = -1
  134. End if
  135. View.Execute
  136. If Err <> 0 Then
  137. Wscript.echo "ERROR: Error executing view: " & SQL
  138. UpdateOsPackage = -1
  139. End if
  140. Wscript.echo " ProductCode Property updated"
  141. 'set package Build
  142. SQL = "UPDATE Property SET Property.Value = '" & dwBuildNumber & "' WHERE Property.Property= 'PackageBuild'"
  143. Set View = Database.OpenView( SQL )
  144. If Err <> 0 Then
  145. Wscript.echo "ERROR: Error opening view: " & SQL
  146. UpdateOsPackage = -1
  147. End if
  148. View.Execute
  149. If Err <> 0 Then
  150. Wscript.echo "ERROR: Error executing view: " & SQL
  151. UpdateOsPackage = -1
  152. End if
  153. Wscript.echo " PackageBuild Property updated"
  154. 'Set the product language property
  155. SQL = "UPDATE Property SET Property.Value = '" & dwLanguage & "' WHERE Property.Property= 'ProductLanguage'"
  156. Set View = Database.OpenView( SQL )
  157. If Err <> 0 Then
  158. Wscript.echo "ERROR: Error opening view: " & SQL
  159. UpdateOsPackage = -1
  160. End if
  161. View.Execute
  162. If Err <> 0 Then
  163. Wscript.echo "ERROR: Error executing view: " & SQL
  164. UpdateOsPackage = -1
  165. End if
  166. Wscript.echo " Product Language Property updated"
  167. 'Set the product version property
  168. SQL = "UPDATE Property SET Property.Value = '5.0." & dwBuildNumber & ".0' WHERE Property.Property= 'ProductVersion'"
  169. Set View = Database.OpenView( SQL )
  170. If Err <> 0 Then
  171. Wscript.echo "ERROR: Error opening view: " & SQL
  172. UpdateOsPackage = -1
  173. End if
  174. View.Execute
  175. If Err <> 0 Then
  176. Wscript.echo "ERROR: Error executing view: " & SQL
  177. UpdateOsPackage = -1
  178. End if
  179. Wscript.echo " ProductVersion Property updated"
  180. 'Commit changes
  181. Database.Commit
  182. If Err <> 0 Then
  183. Wscript.echo "ERROR: Error commiting changes: " & SQL
  184. UpdateOsPackage = -1
  185. End if
  186. Wscript.echo " Changes commited"
  187. End Function
  188. ' main()
  189. Set Args = Wscript.Arguments
  190. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  191. If Args.Count <> 4 Then
  192. Usage
  193. End If
  194. szPathToPackage = Args(0)
  195. If not FileSystem.fileExists ( szPathToPackage ) Then
  196. Wscript.echo " invalid path: " & szPathToPackage
  197. Usage
  198. End If
  199. szPlatform = Args(1)
  200. If (UCase( szPlatform ) = "INTEL") or (UCase( szPlatform ) = "X86") or (UCase( szPlatform ) = "I386") or (UCase( szPlatform ) = "IA64") Then
  201. szPlatform = "Intel"
  202. ElseIf (UCase( szPlatform ) = "ALPHA") or (UCase( szPlatform ) = "AXP64") Then
  203. szPlatform = "Alpha"
  204. Else
  205. Wscript.echo " invalid pltform: " & szPlatform
  206. Usage
  207. End If
  208. dwBuild = Args(2)
  209. If not isNumeric( dwBuild ) Then
  210. Wscript.echo " invalid build number: " & dwBuild
  211. Usage
  212. End If
  213. dwLang = Args(3)
  214. If not isNumeric( dwLang ) Then
  215. If not isNumeric( IntFromHex( dwlang ) ) Then
  216. Wscript.echo " invalid Language: " & dwLang
  217. Usage
  218. Else
  219. dwLang = IntFromHex( dwlang )
  220. End If
  221. End If
  222. wscript.echo szPathToPackage, szPlatform, Int( dwBuild ), dwLang
  223. status = UpdateOsPackage( szPathToPackage, szPlatform, Int( dwBuild ), dwLang )
  224. Wscript.Quit status