Lenard Lindstrom committed 14af88e

msi: add an example program for extracting cabs from .msi files

Comments (0)

Files changed (1)

+# Program
+"""Extract all cabinet embedded in an .msi file.
+Usage:  python <.msi file>
+Cab files are written to the current directory and are named after their
+entries in the Media table.
+This is a demonstation of the msidb module.
+import sys
+import msidb
+def main(msi_file_path):
+    print ("Processing %s" % msi_file_path)
+    con = msidb.connect(msi_file_path)
+    try:
+        cur = con.cursor()
+        cur.execute("select Cabinet from Media")
+        for cabinet, in cur:
+            if cabinet.startswith('#'):
+                name = cabinet[1:]
+                cur.execute("select Data from _Streams where Name=?", (name,))
+                cab_file_name = "" % name
+                data, = cur.fetchone()
+                print ("Writing %s..." % cab_file_name)
+                cab_file = open(cab_file_name, 'wb')
+                try:
+                    cab_file.write(data)
+                finally:
+                    cab_file.close()
+    finally:
+        con.close()
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print ("usage: python <.msi file>")
+    else:
+        main(sys.argv[1])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.