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.

156 lines
4.5 KiB

  1. '
  2. ' Script to update OPK MSI package
  3. '
  4. '
  5. ' Uses uuidgen.exe to generate a GUID, then formats it to be
  6. ' a MSI acceptable string guid
  7. '
  8. ' This makes use of a temporary file %temp%\MakeTempGUID.txt
  9. '
  10. Function MakeGuid()
  11. Dim WSHShell, FileSystem, File, ret, TempFileName, regEx
  12. Set WSHShell = CreateObject("WScript.Shell")
  13. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  14. TempFileName = WSHShell.ExpandEnvironmentStrings("%temp%\MakeTempGUID.txt")
  15. If FileSystem.fileExists(TempFileName) Then
  16. FileSystem.DeleteFile TempFileName
  17. End If
  18. ret = WSHShell.Run("uuidgen -o" & TempFileName, 2, True)
  19. If FileSystem.fileExists(TempFileName) Then
  20. Set File = FileSystem.OpenTextFile(TempFileName, 1)
  21. MakeGuid = "{" & UCase(File.ReadLine) & "}"
  22. File.Close
  23. FileSystem.DeleteFile TempFileName
  24. wscript.echo " Generated GUID: " & MakeGuid
  25. Else
  26. MakeGuid = "{00000000-0000-0000-0000-000000000000}"
  27. Wscript.echo " ERROR: Failed to generate GUID"
  28. End If
  29. Exit Function
  30. End Function
  31. '
  32. ' Updates the OS install MSI package using the following paramaters
  33. ' szPackage - path to package to update. requires read/write access
  34. '
  35. Function UpdateOsPackage( szPackage )
  36. Dim WSHShell, Installer, Database, SummaryInfo, View, SQL
  37. Wscript.echo " Package name : " & szPackage
  38. UpdateOsPackage = 0
  39. On Error Resume Next
  40. '
  41. 'Create the MSI API object
  42. '
  43. Set Installer = CreateObject("WindowsInstaller.Installer")
  44. If Err <> 0 Then
  45. Err = 0
  46. Set Installer = CreateObject("WindowsInstaller.Application")
  47. End If
  48. If Err <> 0 Then
  49. Err = 0
  50. Set Installer = CreateObject("Msi.ApiAutomation")
  51. End If
  52. If Err <> 0 Then
  53. Err = 0
  54. Wscript.echo "ERROR: Error creating Installer object"
  55. UpdateOsPackage = -1
  56. Exit Function
  57. End If
  58. '
  59. 'Create the WSH shell object
  60. '
  61. Set WSHShell = CreateObject("WScript.Shell")
  62. If Err <> 0 Then
  63. Wscript.echo "ERROR: Error creating WSHShell object"
  64. UpdateOsPackage = -1
  65. Exit Function
  66. End If
  67. '
  68. 'Open the package
  69. '
  70. Set Database = Installer.OpenDatabase(szPackage, 1)
  71. If Err <> 0 Then
  72. Wscript.echo "ERROR: Error opening database"
  73. UpdateOsPackage = -1
  74. Exit Function
  75. End If
  76. Wscript.echo " Database opened for update"
  77. '
  78. 'Generate and set a new package code
  79. '
  80. Set SummaryInfo = Database.SummaryInformation(3)
  81. If Err <> 0 Then
  82. Wscript.echo "ERROR: Creating Summary Info Object"
  83. UpdateOsPackage = -1
  84. Exit Function
  85. End If
  86. '
  87. ' Set the Package code
  88. '
  89. Err=0
  90. SummaryInfo.Property(9) = MakeGuid()
  91. If Err <> 0 Then
  92. Wscript.echo "ERROR: Error setting package code"
  93. UpdateOsPackage = -1
  94. Exit Function
  95. End If
  96. Wscript.echo " Successfully updated package Code"
  97. '-------------------------------------------------
  98. 'Generate and set a new product code
  99. '-------------------------------------------------
  100. SQL = "UPDATE Property SET Property.Value = '" & MakeGuid() & "' WHERE Property.Property= 'ProductCode'"
  101. Set View = Database.OpenView(SQL)
  102. If Err <> 0 Then
  103. Wscript.echo "ERROR: Error opening view: " & SQL
  104. UpdateOsPackage = -1
  105. Exit Function
  106. End If
  107. View.Execute
  108. If Err <> 0 Then
  109. Wscript.echo "ERROR: Error executing view: " & SQL
  110. UpdateOsPackage = -1
  111. Exit Function
  112. End If
  113. Wscript.echo " Succesfully updated Product Code"
  114. '-------------------------------------------------
  115. 'Persist the summary info
  116. '-------------------------------------------------
  117. SummaryInfo.Persist
  118. If Err <> 0 Then
  119. Wscript.echo "ERROR: Error persisting summary info"
  120. UpdateOsPackage = -1
  121. Exit Function
  122. End If
  123. Wscript.echo " Successfully persisted summary stream"
  124. 'Commit changes
  125. Database.Commit
  126. If Err <> 0 Then
  127. Wscript.echo "ERROR: Error commiting changes: " & SQL
  128. UpdateOsPackage = -1
  129. Exit Function
  130. End If
  131. Wscript.echo " Successfully commited changes to opk.msi"
  132. End Function
  133. Set Args = Wscript.Arguments
  134. Status = UpdateOsPackage ( Args ( 0 ) )
  135. if Status = -1 Then
  136. Wscript.echo "Failed to update opk.msi"
  137. End if
  138. Wscript.Quit Status