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.

479 lines
15 KiB

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