I need info on editing msi's with vbscript

Posted on 2006-03-31
Last Modified: 2013-11-14
Does anyone have any tutorials on this ?
Question by:itbabe
    1 Comment
    LVL 3

    Accepted Solution

    Try the Windows Installer SDK, you can download it from MS

    Some Sample like this scipt and an help is offered

    ' Windows Installer utility to execute SQL statements against an installer database
    ' For use with Windows Scripting Host, CScript.exe or WScript.exe
    ' Copyright (c) 1999, Microsoft Corporation
    ' Demonstrates the script-driven database queries and updates
    Option Explicit

    Const msiOpenDatabaseModeReadOnly = 0
    Const msiOpenDatabaseModeTransact = 1

    Dim argNum, argCount:argCount = Wscript.Arguments.Count
    If (argCount < 2) Then
          Wscript.Echo "Windows Installer utility to execute SQL queries against an installer database." &_
                vbLf & " The 1st argument specifies the path to the MSI database, relative or full path" &_
                vbLf & " Subsequent arguments specify SQL queries to execute - must be in double quotes" &_
                vbLf & " SELECT queries will display the rows of the result list specified in the query" &_
                vbLf & " Binary data columns selected by a query will not be displayed"
          Wscript.Quit 1
    End If

    ' Scan arguments for valid SQL keyword and to determine if any update operations
    Dim openMode : openMode = msiOpenDatabaseModeReadOnly
    For argNum = 1 To argCount - 1
          Dim keyword : keyword = Wscript.Arguments(argNum)
          Dim keywordLen : keywordLen = InStr(1, keyword, " ", vbTextCompare)
          If (keywordLen) Then keyword = UCase(Left(keyword, keywordLen - 1))
          If InStr(1, "UPDATE INSERT DELETE CREATE ALTER DROP", keyword, vbTextCompare) Then
                openMode = msiOpenDatabaseModeTransact
          ElseIf keyword <> "SELECT" Then
                Fail "Invalid SQL statement type: " & keyword
          End If

    ' Connect to Windows installer object
    On Error Resume Next
    Dim installer : Set installer = Nothing
    Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError

    ' Open database
    Dim databasePath:databasePath = Wscript.Arguments(0)
    Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError

    ' Process SQL statements
    Dim query, view, record, message, rowData, columnCount, delim, column
    For argNum = 1 To argCount - 1
          query = Wscript.Arguments(argNum)
          Set view = database.OpenView(query) : CheckError
          view.Execute : CheckError
          If Ucase(Left(query, 6)) = "SELECT" Then
                      Set record = view.Fetch
                      If record Is Nothing Then Exit Do
                      columnCount = record.FieldCount
                      rowData = Empty
                      delim = "  "
                      For column = 1 To columnCount
                            If column = columnCount Then delim = vbLf
                            rowData = rowData & record.StringData(column) & delim
                      message = message & rowData
          End If
    If openMode = msiOpenDatabaseModeTransact Then database.Commit
    If Not IsEmpty(message) Then Wscript.Echo message
    Wscript.Quit 0

    Sub CheckError
          Dim message, errRec
          If Err = 0 Then Exit Sub
          message = Err.Source & " " & Hex(Err) & ": " & Err.Description
          If Not installer Is Nothing Then
                Set errRec = installer.LastErrorRecord
                If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
          End If
          Fail message
    End Sub

    Sub Fail(message)
          Wscript.Echo message
          Wscript.Quit 2
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    twoTwo  challenge 35 71
    countClumps  challenge 10 68
    count7 challenge 12 52
    VOB to mp3 8 20
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now