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.

132 lines
3.5 KiB

  1. ' Wise for Windows Installer utility to delete files associated to a wildcard specification
  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. Const msiViewModifyDelete = 6
  11. Dim argNum, argCount:argCount = Wscript.Arguments.Count
  12. If (argCount < 1) Then
  13. Wscript.Echo "Usage: DeleteWildcardFiles.vbs <path to MSI or WSI>"
  14. Wscript.Quit 1
  15. End If
  16. 'Dim openMode : openMode = msiOpenDatabaseModeReadOnly
  17. Dim openMode : openMode = msiOpenDatabaseModeTransact
  18. ' Connect to Windows installer object
  19. On Error Resume Next
  20. Dim installer : Set installer = Nothing
  21. Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
  22. ' Open database
  23. Dim databasePath:databasePath = Wscript.Arguments(0)
  24. Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError
  25. ' Process SQL statements
  26. Dim query, view, record, sAllPaths, sPath, nPos
  27. query = "SELECT Path FROM WiseWildcard"
  28. Set view = database.OpenView(query) : CheckError
  29. view.Execute : CheckError
  30. Do
  31. Set record = view.Fetch
  32. If record Is Nothing Then Exit Do
  33. sPath = Empty
  34. sPath = record.StringData(1)
  35. nPos = InStr(sPath, "]")
  36. If nPos > 0 Then sPath = Mid(sPath, nPos + 1)
  37. If IsEmpty(sAllPaths) Then
  38. sAllPaths = sPath
  39. Else
  40. sAllPaths = sAllPaths & "," & sPath
  41. End If
  42. Loop
  43. view.Close
  44. Dim arrPaths, i
  45. arrPaths = Split(sAllPaths, ",")
  46. For i = 0 to UBound(arrPaths)
  47. Wscript.Echo "Wildcard path: " & arrPaths(i)
  48. DeleteWildcardFiles(arrPaths(i))
  49. Next
  50. If openMode = msiOpenDatabaseModeTransact Then database.Commit
  51. Wscript.Quit 0
  52. Sub DeleteWildcardFiles(sWildcardPath)
  53. Dim sSourcePath, sFile, sFiles
  54. sFiles = Empty
  55. query = "SELECT File_, SourcePath FROM WiseSourcePath"
  56. Set view = database.OpenView(query) : CheckError
  57. view.Execute : CheckError
  58. Do
  59. Set record = view.Fetch
  60. If record Is Nothing Then Exit Do
  61. sFile = Empty
  62. sFile = record.StringData(1)
  63. sSourcePath = Empty
  64. sSourcePath = record.StringData(2)
  65. If InStr(sSourcePath, sWildcardPath) > 0 Then
  66. ' Only add the file to the deletion list if it is not the keypath of a component
  67. Dim query2, record2, view2
  68. query2 = "SELECT KeyPath FROM Component WHERE KeyPath = '" & sFile & "'"
  69. Set view2 = database.OpenView(query2) : CheckError
  70. view2.Execute : CheckError
  71. Set record2 = view2.Fetch
  72. If record2 Is Nothing Then
  73. If IsEmpty(sFiles) Then
  74. sFiles = sFile
  75. Else
  76. sFiles = sFiles & "," & sFile
  77. End If
  78. End If
  79. view2.Close
  80. End If
  81. Loop
  82. view.Close
  83. Dim arrFiles, i
  84. arrFiles = Split(sFiles, ",")
  85. For i = 0 to UBound(arrFiles)
  86. If openMode = msiOpenDatabaseModeTransact Then
  87. query = "DELETE FROM WiseSourcePath WHERE File_ = '" & arrFiles(i) & "'"
  88. Set view = database.OpenView(query) : CheckError
  89. view.Execute : CheckError
  90. view.Close
  91. query = "DELETE FROM File WHERE File = '" & arrFiles(i) & "'"
  92. Set view = database.OpenView(query) : CheckError
  93. view.Execute : CheckError
  94. view.Close
  95. Else
  96. Wscript.Echo i & ": " & arrFiles(i)
  97. End If
  98. Next
  99. End Sub
  100. Sub CheckError
  101. Dim message, errRec
  102. If Err = 0 Then Exit Sub
  103. message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  104. If Not installer Is Nothing Then
  105. Set errRec = installer.LastErrorRecord
  106. If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
  107. End If
  108. Fail message
  109. End Sub
  110. Sub Fail(message)
  111. Wscript.Echo message
  112. Wscript.Quit 2
  113. End Sub