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.

104 lines
2.9 KiB

  1. '
  2. ' Updates an MSI package using the following paramaters
  3. ' szPackage - path to package to update. requires read/write access
  4. ' szBuildNumber - 4 digit build number of the current build, i.e 3610
  5. '
  6. ' Syntax: cscript updatever.vbs package_path build_number
  7. '
  8. '
  9. Sub Usage
  10. Wscript.echo "SYNTAX:"
  11. Wscript.echo "cscript updatever.vbs <package_path> <build_number>"
  12. Wscript.echo " <package_path> - path to package to update. requires read/write access"
  13. Wscript.echo " <build_number> - 4 digit build number of the current build, i.e 3456"
  14. Wscript.Quit -1
  15. End Sub
  16. Function UpdateVer(szPackage, szBuildNumber )
  17. Dim WSHShell, Installer, Database, SummaryInfo, Record, View, SQL
  18. Wscript.echo "Updating MSI package: " & szPackage
  19. Wscript.echo " Build: " & szBuildNumber
  20. UpdateVer = 0
  21. On Error Resume Next
  22. 'Create the MSI API object
  23. Set Installer = CreateObject("WindowsInstaller.Installer")
  24. If Err <> 0 Then
  25. Set Installer = CreateObject("WindowsInstaller.Application")
  26. End If
  27. If Err <> 0 Then
  28. Set Installer = CreateObject("Msi.ApiAutomation")
  29. End if
  30. If Err <> 0 Then
  31. Wscript.echo "ERROR: Error creating Installer object"
  32. UpdateVer = -1
  33. End if
  34. 'Create the WSH shell object
  35. Set WSHShell = CreateObject("WScript.Shell")
  36. If Err <> 0 Then
  37. Wscript.echo "ERROR: Error creating WSHShell object"
  38. UpdateVer = -1
  39. End if
  40. 'Open the package
  41. Set Database = Installer.OpenDatabase(szPackage, 1)
  42. If Err <> 0 Then
  43. Wscript.echo "ERROR: Error opening database"
  44. UpdateVer = -1
  45. End if
  46. Wscript.echo " Database opened for update"
  47. 'Set the product version property
  48. SQL = "UPDATE Property SET Property.Value = '5.2." & szBuildNumber & "' WHERE Property.Property= 'ProductVersion'"
  49. Set View = Database.OpenView( SQL )
  50. If Err <> 0 Then
  51. Wscript.echo Err.Number
  52. Wscript.echo "ERROR: Error opening view: " & SQL
  53. UpdateVer = -1
  54. End if
  55. View.Execute
  56. If Err <> 0 Then
  57. Wscript.echo "ERROR: Error executing view: " & SQL
  58. UpdateVer = -1
  59. End if
  60. Wscript.echo " ProductVersion Property updated"
  61. 'Commit changes
  62. Database.Commit
  63. If Err <> 0 Then
  64. Wscript.echo "ERROR: Error commiting changes: " & SQL
  65. UpdateVer = -1
  66. End if
  67. Wscript.echo " Changes commited"
  68. End Function
  69. ' main()
  70. Set Args = Wscript.Arguments
  71. Set FileSystem = CreateObject("Scripting.FileSystemObject")
  72. If Args.Count <> 2 Then
  73. Usage
  74. End If
  75. szPathToPackage = Args(0)
  76. If not FileSystem.fileExists ( szPathToPackage ) Then
  77. Wscript.echo "ERROR: Invalid path: " & szPathToPackage
  78. Usage
  79. End If
  80. szBuild = Args(1)
  81. iLen = Len(szBuild)
  82. If (iLen <= 0) Or (iLen >4) Then
  83. Wscript.echo "ERROR: Invalid build number: " & szBuild
  84. Usage
  85. End If
  86. wscript.echo szPathToPackage, szBuild
  87. status = UpdateVer( szPathToPackage, szBuild )
  88. Wscript.Quit status