Source code of Windows XP (NT5)
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.

471 lines
14 KiB

  1. '
  2. ' Script to update OS install MSI package
  3. ' Syntax: cscript OsPack.vbs package_path platform build_number language_number info_file
  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.echo " info_file - File containing information in Valuename = Value format"
  14. Wscript.Quit -1
  15. End Sub
  16. ' takes a string of the form 0x409 and converts it to an int
  17. Function IntFromHex(szInHexString)
  18. szHexString = szInHexString
  19. IntFromHex = 0
  20. multiplier = 1
  21. While (UCase(Right(szHexString, 1)) <> "X")
  22. Ch = UCase(Right(szHexString, 1))
  23. Select Case Ch
  24. Case "A" Ch = 10
  25. Case "B" Ch = 11
  26. Case "C" Ch = 12
  27. Case "D" Ch = 13
  28. Case "E" Ch = 14
  29. Case "F" Ch = 15
  30. End Select
  31. IntFromHex = IntFromHex + multiplier * Ch
  32. multiplier = multiplier * 16
  33. szHexString = Left(szHexString, Len(szHexString) - 1)
  34. Wend
  35. Exit Function
  36. End Function
  37. '
  38. ' Uses uuidgen.exe to generate a GUID, then formats it to be
  39. ' a MSI acceptable string guid
  40. '
  41. ' This makes use of a temporary file %temp%\MakeTempGUID.txt
  42. '
  43. Function MakeGuid()
  44. Dim WSHShell, FileSystem, File, ret, TempFileName, regEx
  45. Set WSHShell = CreateObject("WScript.Shell")
  46. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  47. TempFileName = WSHShell.ExpandEnvironmentStrings("%temp%\MakeTempGUID.txt")
  48. If FileSystem.fileExists(TempFileName) Then
  49. FileSystem.DeleteFile TempFileName
  50. End If
  51. ret = WSHShell.Run("uuidgen -o" & TempFileName, 2, True)
  52. If FileSystem.fileExists(TempFileName) Then
  53. Set File = FileSystem.OpenTextFile(TempFileName, 1)
  54. MakeGuid = "{" & UCase(File.ReadLine) & "}"
  55. File.Close
  56. FileSystem.DeleteFile TempFileName
  57. Wscript.echo " Generated GUID: " & MakeGuid
  58. Else
  59. MakeGuid = "{00000000-0000-0000-0000-000000000000}"
  60. Wscript.echo " ERROR: Failed to generate GUID"
  61. End If
  62. Exit Function
  63. End Function
  64. Function GetToken(szFile, szValue)
  65. Dim FileSystem, File, Line, regEx, Matches, Match
  66. GetToken = Empty
  67. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  68. If Err <> 0 Then
  69. Wscript.echo "ERROR: Error creating filesystem object"
  70. End If
  71. szPathToFile = FileSystem.GetAbsolutePathName(szFile) ' Gets current directory
  72. If FileSystem.fileExists(szPathToFile) Then
  73. Set File = FileSystem.OpenTextFile(szPathToFile, 1) 'Open up the file
  74. If Err <> 0 Then
  75. Wscript.echo "ERROR: Error opening file " & szPathToFile
  76. End If
  77. Do While File.AtEndOfStream <> True
  78. Line = File.ReadLine
  79. Set regEx = New RegExp
  80. If Err <> 0 Then
  81. Wscript.echo "ERROR: Error creating RegExp object"
  82. End If
  83. regEx.Pattern = szValue & " *=+ *" ' Look for valuename = Value entry
  84. regEx.IgnoreCase = False
  85. regEx.Global = False
  86. Set Matches = regEx.Execute(Line)
  87. For Each Match In Matches
  88. ValueIndex = Match.FirstIndex + Match.Length + 1
  89. GetToken = Mid(Line, ValueIndex)
  90. Exit Function
  91. Next
  92. Loop
  93. If Matches.Count = 0 Then
  94. Wscript.echo "Error: Could not find " & szValue & " in " & szFile
  95. End If
  96. Else
  97. Wscript.echo "ERROR: " & szPathToFile & " not present"
  98. End If
  99. Exit Function
  100. End Function
  101. '
  102. ' Updates the OS install MSI package using the following paramaters
  103. ' szPackage - path to package to update. requires read/write access
  104. ' szPlatform - must be either "Alpha" or "Intel"
  105. ' dwBuildNumber - 4 digit build number of the current build, i.e 1877
  106. ' dwLanguage - Language Id of the desired language, i.e. 1033 = US English, 0=Neutral
  107. '
  108. Function UpdateOsPackage(szPackage, szPlatform, dwBuildNumber, dwLanguage, szInfoFile)
  109. Dim WSHShell, Installer, Database, SummaryInfo, Record, View, SQL
  110. Wscript.echo "Updating OS install package: " & szPackage
  111. Wscript.echo " For: " & szPlatform
  112. Wscript.echo " Build: " & dwBuildNumber
  113. Wscript.echo " Lang: " & dwLanguage
  114. UpdateOsPackage = 0
  115. Err = 0
  116. On Error Resume Next
  117. 'Create the MSI API object
  118. Set Installer = CreateObject("WindowsInstaller.Installer")
  119. If Err <> 0 Then
  120. Err = 0
  121. Set Installer = CreateObject("WindowsInstaller.Application")
  122. End If
  123. If Err <> 0 Then
  124. Err = 0
  125. Set Installer = CreateObject("Msi.ApiAutomation")
  126. End If
  127. If Err <> 0 Then
  128. Err = 0
  129. Wscript.echo "ERROR: Error creating Installer object"
  130. UpdateOsPackage = -1
  131. Exit Function
  132. End If
  133. 'Create the WSH shell object
  134. Set WSHShell = CreateObject("WScript.Shell")
  135. If Err <> 0 Then
  136. Wscript.echo "ERROR: Error creating WSHShell object"
  137. UpdateOsPackage = -1
  138. Exit Function
  139. End If
  140. 'Open the package
  141. Set Database = Installer.OpenDatabase(szPackage, 1)
  142. If Err <> 0 Then
  143. Wscript.echo "ERROR: Error opening database"
  144. UpdateOsPackage = -1
  145. Exit Function
  146. End If
  147. Wscript.echo " Database opened for update"
  148. 'Generate and set a new package code
  149. Set SummaryInfo = Database.SummaryInformation(3)
  150. If Err <> 0 Then
  151. Wscript.echo "ERROR: Creating Summary Info Object"
  152. UpdateOsPackage = -1
  153. Exit Function
  154. End If
  155. '-------------------------------------------------
  156. ' Remove the not needed Summary fields
  157. '-------------------------------------------------
  158. SummaryInfo.Property(3) = Empty 'Subject
  159. SummaryInfo.Property(4) = Empty 'Author
  160. SummaryInfo.Property(5) = Empty 'Keywords
  161. SummaryInfo.Property(6) = Empty 'Comments
  162. SummaryInfo.Property(8) = Empty 'Last Saved by
  163. SummaryInfo.Property(13) = Empty 'Last Save Time
  164. Err=0
  165. SummaryInfo.Property(9) = MakeGuid()
  166. If Err <> 0 Then
  167. Wscript.echo "ERROR: Error setting package code"
  168. UpdateOsPackage = -1
  169. Exit Function
  170. End If
  171. Wscript.echo " Updated package Code"
  172. '-------------------------------------------------
  173. 'Update Platform and Language list
  174. '-------------------------------------------------
  175. SummaryInfo.Property(7) = szPlatform & ";" & dwLanguage
  176. If Err <> 0 Then
  177. Wscript.echo "ERROR: Error setting platform and language list"
  178. UpdateOsPackage = -1
  179. Exit Function
  180. End If
  181. Wscript.echo " Updated Language and platform list to: " & szPlatform & ";" & dwLanguage
  182. '-------------------------------------------------
  183. 'Get Product Name from szInfoFile and Set
  184. '-------------------------------------------------
  185. szProductName = GetToken(szInfoFile, "ProductName")
  186. If IsEmpty(szProductName) Then
  187. Wscript.echo "ERROR: Error getting Product Name from " & szInfoFile
  188. UpdateOsPackage = -1
  189. Exit Function
  190. End If
  191. SummaryInfo.Property(2) = szProductName
  192. If Err <> 0 Then
  193. Wscript.echo "ERROR: Error setting productname property"
  194. UpdateOsPackage = -1
  195. Exit Function
  196. End If
  197. Wscript.echo " Updated Product Name to: " & szProductName
  198. SummaryInfo.Persist
  199. If Err <> 0 Then
  200. Wscript.echo "ERROR: Error persisting summary info"
  201. UpdateOsPackage = -1
  202. Exit Function
  203. End If
  204. Wscript.echo " persisted summary stream"
  205. SQL = "UPDATE Property SET Property.Value = '" & szProductName & "' WHERE Property.Property= 'ProductName'"
  206. Set View = Database.OpenView(SQL)
  207. If Err <> 0 Then
  208. Wscript.echo "ERROR: Error executing view: " & SQL
  209. UpdateOsPackage = -1
  210. Exit Function
  211. End If
  212. View.Execute
  213. If Err <> 0 Then
  214. Wscript.echo "ERROR: Error executing view: " & SQL
  215. UpdateOsPackage = -1
  216. Exit Function
  217. End If
  218. Wscript.echo " ProductName Property updated"
  219. '-------------------------------------------------
  220. 'Generate and set a new product code
  221. '-------------------------------------------------
  222. SQL = "UPDATE Property SET Property.Value = '" & MakeGuid() & "' WHERE Property.Property= 'ProductCode'"
  223. Set View = Database.OpenView(SQL)
  224. If Err <> 0 Then
  225. Wscript.echo "ERROR: Error opening view: " & SQL
  226. UpdateOsPackage = -1
  227. Exit Function
  228. End If
  229. View.Execute
  230. If Err <> 0 Then
  231. Wscript.echo "ERROR: Error executing view: " & SQL
  232. UpdateOsPackage = -1
  233. Exit Function
  234. End If
  235. Wscript.echo " ProductCode Property updated"
  236. '-------------------------------------------------
  237. 'set package Build
  238. '-------------------------------------------------
  239. SQL = "UPDATE Property SET Property.Value = '" & dwBuildNumber & "' WHERE Property.Property= 'PackageBuild'"
  240. Set View = Database.OpenView(SQL)
  241. If Err <> 0 Then
  242. Wscript.echo "ERROR: Error opening view: " & SQL
  243. UpdateOsPackage = -1
  244. Exit Function
  245. End If
  246. View.Execute
  247. If Err <> 0 Then
  248. Wscript.echo "ERROR: Error executing view: " & SQL
  249. UpdateOsPackage = -1
  250. Exit Function
  251. End If
  252. Wscript.echo " PackageBuild Property updated"
  253. '-------------------------------------------------
  254. 'Set the product language property
  255. '-------------------------------------------------
  256. SQL = "UPDATE Property SET Property.Value = '" & dwLanguage & "' WHERE Property.Property= 'ProductLanguage'"
  257. Set View = Database.OpenView(SQL)
  258. If Err <> 0 Then
  259. Wscript.echo "ERROR: Error opening view: " & SQL
  260. UpdateOsPackage = -1
  261. Exit Function
  262. End If
  263. View.Execute
  264. If Err <> 0 Then
  265. Wscript.echo "ERROR: Error executing view: " & SQL
  266. UpdateOsPackage = -1
  267. Exit Function
  268. End If
  269. Wscript.echo " Product Language Property updated"
  270. '-------------------------------------------------
  271. 'Set the product version property
  272. '-------------------------------------------------
  273. '
  274. SQL = "UPDATE Property SET Property.Value = '5.1." & dwBuildNumber & ".0' WHERE Property.Property= 'ProductVersion'"
  275. Set View = Database.OpenView(SQL)
  276. If Err <> 0 Then
  277. Wscript.echo "ERROR: Error opening view: " & SQL
  278. UpdateOsPackage = -1
  279. Exit Function
  280. End If
  281. View.Execute
  282. If Err <> 0 Then
  283. Wscript.echo "ERROR: Error executing view: " & SQL
  284. UpdateOsPackage = -1
  285. Exit Function
  286. End If
  287. Wscript.echo " ProductVersion Property updated"
  288. '-------------------------------------------------
  289. 'Set the DialogCaption property
  290. '-------------------------------------------------
  291. '
  292. szDialogCaption = GetToken(szInfoFile, "DialogCaption")
  293. If IsEmpty(szDialogCaption) Then
  294. Wscript.echo "ERROR: Error getting DialogCaption from " & szInfoFile
  295. UpdateOsPackage = -1
  296. Exit Function
  297. End If
  298. SQL = "UPDATE Property SET Property.Value = '" & szDialogCaption & "' WHERE Property.Property= 'DialogCaption'"
  299. Set View = Database.OpenView(SQL)
  300. If Err <> 0 Then
  301. Wscript.echo "ERROR: Error opening view: " & SQL
  302. UpdateOsPackage = -1
  303. Exit Function
  304. End If
  305. View.Execute
  306. If Err <> 0 Then
  307. Wscript.echo "ERROR: Error executing view: " & SQL
  308. UpdateOsPackage = -1
  309. Exit Function
  310. End If
  311. Wscript.echo " DialogCaption Property updated"
  312. '-------------------------------------------------
  313. 'Set the DiskPrompt property
  314. '-------------------------------------------------
  315. '
  316. 'szDiskPrompt = GetToken(szInfoFile, "DiskPrompt")
  317. 'If IsEmpty(szDiskPrompt) Then
  318. ' Wscript.echo "ERROR: Error getting DiskPrompt from " & szInfoFile
  319. ' UpdateOsPackage = -1
  320. ' Exit Function
  321. 'End If
  322. '
  323. 'SQL = "UPDATE Property SET Property.Value = '" & szDiskPrompt & "' WHERE Property.Property= 'DiskPrompt'"
  324. 'Set View = Database.OpenView(SQL)
  325. ' If Err <> 0 Then
  326. ' Wscript.echo "ERROR: Error opening view: " & SQL
  327. ' UpdateOsPackage = -1
  328. ' Exit Function
  329. 'End If
  330. 'View.Execute
  331. 'If Err <> 0 Then
  332. ' Wscript.echo "ERROR: Error executing view: " & SQL
  333. ' UpdateOsPackage = -1
  334. ' Exit Function
  335. 'End If
  336. 'Wscript.echo " DiskPrompt Property updated"
  337. 'Commit changes
  338. Database.Commit
  339. If Err <> 0 Then
  340. Wscript.echo "ERROR: Error commiting changes: " & SQL
  341. UpdateOsPackage = -1
  342. Exit Function
  343. End If
  344. Wscript.echo " Changes commited"
  345. End Function
  346. ' main()
  347. Set Args = Wscript.Arguments
  348. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  349. If Args.Count <> 5 Then
  350. Usage
  351. End If
  352. szPathToPackage = Args(0)
  353. If Not FileSystem.fileExists(szPathToPackage) Then
  354. Wscript.echo " invalid path: " & szPathToPackage
  355. Usage
  356. End If
  357. szPlatform = Args(1)
  358. If (UCase(szPlatform) = "INTEL") Or (UCase(szPlatform) = "X86") Or (UCase(szPlatform) = "I386") Or (UCase(szPlatform) = "IA64") Then
  359. szPlatform = "Intel"
  360. ElseIf (UCase(szPlatform) = "ALPHA") Or (UCase(szPlatform) = "AXP64") Then
  361. szPlatform = "Alpha"
  362. Else
  363. Wscript.echo " invalid pltform: " & szPlatform
  364. Usage
  365. End If
  366. dwBuild = Args(2)
  367. If Not IsNumeric(dwBuild) Then
  368. Wscript.echo " invalid build number: " & dwBuild
  369. Usage
  370. End If
  371. dwLang = Args(3)
  372. If Not IsNumeric(dwLang) Then
  373. If Not IsNumeric(IntFromHex(dwLang)) Then
  374. Wscript.echo " invalid Language: " & dwLang
  375. Usage
  376. Else
  377. dwLang = IntFromHex(dwLang)
  378. End If
  379. End If
  380. szInfoFile = Args(4)
  381. Wscript.echo szPathToPackage, szPlatform, Int(dwBuild), dwLang, szInfoFile
  382. Status = UpdateOsPackage(szPathToPackage, szPlatform, Int(dwBuild), dwLang, szInfoFile)
  383. Wscript.Quit Status