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.

496 lines
16 KiB

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