|
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Installer
Dim Database
Dim View
Dim Record
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
Friend WithEvents DataView1 As System.Data.DataView
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.ListView1 = New System.Windows.Forms.ListView
Me.Splitter1 = New System.Windows.Forms.Splitter
Me.DataView1 = New System.Data.DataView
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.MenuItem1 = New System.Windows.Forms.MenuItem
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'OpenFileDialog1
'
Me.OpenFileDialog1.Filter = """Microsoft Installer DB (*.msi)|*.msi|All files (*.*)|*.*"""
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
'
'ListView1
'
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Left
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.MultiSelect = False
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(112, 273)
Me.ListView1.SmallImageList = Me.ImageList1
Me.ListView1.StateImageList = Me.ImageList1
Me.ListView1.TabIndex = 0
Me.ListView1.View = System.Windows.Forms.View.SmallIcon
'
'Splitter1
'
Me.Splitter1.Location = New System.Drawing.Point(112, 0)
Me.Splitter1.Name = "Splitter1"
Me.Splitter1.Size = New System.Drawing.Size(3, 273)
Me.Splitter1.TabIndex = 1
Me.Splitter1.TabStop = False
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataView1
Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Fill
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(115, 0)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(177, 273)
Me.DataGrid1.TabIndex = 2
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "&Open"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.Splitter1)
Me.Controls.Add(Me.ListView1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
ListView1.Clear()
Installer = CreateObject("WindowsInstaller.Installer")
Database = Installer.OpenDatabase(OpenFileDialog1.FileName, 0) ' 0 = read only; 1 = read/write
' Get table names
View = Database.OpenView("SELECT `Name` FROM `_Tables`")
View.Execute(Record)
Record = View.Fetch()
While Not Record Is Nothing
ListView1.Items.Add(Record.StringData(1), 0)
Record = View.Fetch()
End While
End If
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
If ListView1.SelectedItems.Count = 0 Then
Exit Sub
End If
Installer = CreateObject("WindowsInstaller.Installer")
' Get Column names
View = Database.OpenView("SELECT `Name` FROM `_Columns` WHERE `Table` = '" & ListView1.SelectedItems(0).Text & "' ")
View.Execute(Record)
'
Dim DbColumns As String = ""
Record = View.Fetch()
While Not Record Is Nothing
DbColumns = DbColumns & "`" & Record.StringData(1) & "`"
Record = View.Fetch()
If Not Record Is Nothing Then
DbColumns = DbColumns & ", "
End If
End While
'
View = Database.OpenView("SELECT " & DbColumns & " FROM `" & ListView1.SelectedItems(0).Text & "` ")
View.Execute(Record)
Dim ColumnsAR() As String = Split(DbColumns, "`, `")
ColumnsAR(0) = ColumnsAR(0).TrimStart("`")
ColumnsAR(ColumnsAR.Length - 1) = ColumnsAR((ColumnsAR.Length - 1)).TrimEnd("`"c)
DataView1.Table = New DataTable(ListView1.SelectedItems(0).Text)
For Each TableColumn As String In ColumnsAR
DataView1.Table.Columns.Add(TableColumn, Type.GetType("System.String"))
Next TableColumn
Dim NewRow As DataRow
Record = View.Fetch()
While Not Record Is Nothing
NewRow = DataView1.Table.NewRow()
For I As Integer = 0 To ColumnsAR.Length - 1
Try
NewRow(ColumnsAR(I)) = Record.StringData(I + 1)
Catch ex As Exception
NewRow(ColumnsAR(I)) = "(Binary)"
End Try
Next
DataView1.Table.Rows.Add(NewRow)
Record = View.Fetch()
End While
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Rodolfo Ortega is a Cuban Computer Scientist. He works as IT Auditor for the CIMEX S.A. subsidiary in Holguin, Cuba. He lives and works in Holguin, in the eastern part of the island of Cuba.
You can contact him at rodolfom[]cimex.com.cu for any personal message: Ideas on new articles, bibliography about new APIs, questions, are wellcome.
Submit questions related with current article to the article forum.