mst + .msi表信息。
我创建了以下函数来读取msi表
// This method returns all rows and columns of a Table specified by Name
public DataTable ReadMsiTableByName(string msiFile, string tableName)
{
DataTable msiTable = new DataTable(tableName);
Database database = null;
View view = null;
try
{
using (database = new Database(msiFile, DatabaseOpenMode.ReadOnly))
{
string sqlQuery = String.Format("SELECT * FROM {0}", tableName);
view = database.OpenView(sqlQuery);
view.Execute(null);
Record record = view.Fetch();
ColumnCollection columnCollection = view.Columns;
for (int i = 0; i < columnCollection.Count; i++)
{
string columnName = columnCollection[i].Name.ToString();
System.Type columnType = columnCollection[i].Type;
msiTable.Columns.Add(columnName, columnType.UnderlyingSystemType);
}
while (record != null)
{
DataRow row = msiTable.NewRow();
for (int i = 0; i < columnCollection.Count; i++)
{
string type = columnCollection[i].Type.ToString();
if (type == "System.String")
{
row[columnCollection[i].Name.ToString()] = record.GetString(columnCollection[i].Name.ToString());
}
else if (type == "System.Int16")
{
row[columnCollection[i].Name.ToString()] = record.GetInteger(columnCollection[i].Name.ToString());
}
else if (type == "System.Int32")
{
row[columnCollection[i].Name.ToString()] = record.GetInteger(columnCollection[i].Name.ToString());
}
else if (type == "System.IO.Stream")
{
System.IO.Stream stream;
stream = record.GetStream(columnCollection[i].Name.ToString());
row[columnCollection[i].Name.ToString()] = stream;
}
}
msiTable.Rows.Add(row);
record = view.Fetch();
}
}
}
catch (Exception ex)
{
CommonFn.CreateLog(ex.ToString());
}
finally
{
if (database != null)
database.Close();
if (view != null)
view.Close();
}
return msiTable;
}
但是我无法使用此功能读取.mst。我读过你需要使用msi转换,但是我不想改变msi或mst的内容,我只需要读取所有的表。请指出我正确的方向。在此先感谢:)
答案 0 :(得分:3)
根据定义,MST是变换。它只包含基本MSI的增量。
数据库类有一个名为ViewTransform的方法。如果MST与MSI兼容,它将成功,并且更改将显示在_TransformView表中。
或者,如果您不希望看到更改但是您想要查看最终状态,则可以将MSI复制到临时MSI并使用ApplyTransform方法应用转换然后提交它。现在,您可以使用已有的代码进行查询。
答案 1 :(得分:0)
适合我:
msiDatabase = new Database(@"Foo.msi", DatabaseOpenMode.ReadOnly);
msiDatabase.ApplyTransform(@"Foo.mst");