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.

75 lines
2.5 KiB

  1. ' Wise for Windows Installer utility to change the SourcePath field in the WiseSourcePath table in an installer database
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999, Microsoft Corporation
  4. ' Demonstrates the script-driven database queries and updates
  5. '
  6. Option Explicit
  7. Const msiOpenDatabaseModeReadOnly = 0
  8. Const msiOpenDatabaseModeTransact = 1
  9. Const msiViewModifyUpdate = 2
  10. Dim argNum, argCount:argCount = Wscript.Arguments.Count
  11. If (argCount < 3) Then
  12. Wscript.Echo "Wise for Windows Installer utility to change the SourcePath field in an installer database." &_
  13. vbLf & " The 1st argument specifies the path to the MSI database, relative or full path" &_
  14. vbLf & " The 2nd argument specifies the original SourcePath" &_
  15. vbLf & " The 3rd argument specifies the new SourcePath"
  16. Wscript.Quit 1
  17. End If
  18. 'Dim openMode : openMode = msiOpenDatabaseModeReadOnly
  19. Dim openMode : openMode = msiOpenDatabaseModeTransact
  20. ' Connect to Windows installer object
  21. On Error Resume Next
  22. Dim installer : Set installer = Nothing
  23. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  24. ' Open database
  25. Dim databasePath:databasePath = Wscript.Arguments(0)
  26. Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError
  27. Dim sOldSourcePath:sOldSourcePath = Wscript.Arguments(1)
  28. Dim sNewSourcePath:sNewSourcePath = Wscript.Arguments(2)
  29. ' Process SQL statements
  30. Dim query, view, record, sSourcePath, sModifiedPath
  31. query = "SELECT SourcePath FROM WiseSourcePath"
  32. Set view = database.OpenView(query) : CheckError
  33. view.Execute : CheckError
  34. Do
  35. Set record = view.Fetch
  36. If record Is Nothing Then Exit Do
  37. sSourcePath = Empty
  38. sModifiedPath = Empty
  39. sSourcePath = record.StringData(1)
  40. If InStr(UCase(sSourcePath), UCase(sOldSourcePath)) Then
  41. sModifiedPath = Replace(sSourcePath, sOldSourcePath, sNewSourcePath, 1, 1, 1)
  42. If openMode = msiOpenDatabaseModeTransact Then
  43. record.StringData(1) = sModifiedPath
  44. view.Modify msiViewModifyUpdate, record
  45. End If
  46. Wscript.Echo "Old: " & sSourcePath
  47. Wscript.Echo "New: " & sModifiedPath & vbLf
  48. End If
  49. Loop
  50. view.Close
  51. If openMode = msiOpenDatabaseModeTransact Then database.Commit
  52. Wscript.Quit 0
  53. Sub CheckError
  54. Dim message, errRec
  55. If Err = 0 Then Exit Sub
  56. message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  57. If Not installer Is Nothing Then
  58. Set errRec = installer.LastErrorRecord
  59. If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
  60. End If
  61. Fail message
  62. End Sub
  63. Sub Fail(message)
  64. Wscript.Echo message
  65. Wscript.Quit 2
  66. End Sub