【发布时间】:2013-05-27 10:09:58
【问题描述】:
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 的内容,我只需要阅读所有表格。请指出我正确的方向。提前致谢:)
【问题讨论】:
-
顺便说一句,你没有处理你的一些课程。结帐:stackoverflow.com/questions/14020285/…
-
感谢您指出 :) 将明确处理它们。 (我知道处理您使用的所有内容的好习惯,但它不会被 .net GC 自动处理吗?只是好奇。但再次感谢)
-
最终。但是这些类有非托管(p/invoke)句柄,需要更及时地处理。
标签: c# wix windows-installer wix3.7 dtf