Discussion:
Extracting File from MSI in C#
(too old to reply)
Craig Dahlinger
2004-05-13 15:36:09 UTC
Permalink
Hey all, I am very new to MSI, but I am trying to do something very simple.
I want to extract the files out of an MSI and get FileVersionInfo oneach
file. I am able to open the database, create view, and get file names for
example, but where are the actual files being stored to extract. I am
assuming they are in binary format so I would have to do a binary
extraction, but I cannot find any examples on the internet or anywhere
please help...

Here is the C# code I got so far:

public static bool ExtractMSIInfo(string MSIFile, int iHotFixId)
{

WindowsInstaller.Installer oInstaller;
oInstaller = (WindowsInstaller.Installer)new
WindowsInstaller.InstallerClass();
WindowsInstaller.Database oDataBase = null;
WindowsInstaller.View oView = null;


try
{
//open database
oDataBase =
oInstaller.OpenDatabase(MSIFile,WindowsInstaller.MsiOpenDatabaseMode.msiOpen
DatabaseModeReadOnly);
//create view
oView = oDataBase.OpenView("SELECT FileName FROM File");
//create record holder
WindowsInstaller.Record oRecord = null;;
//execute query
oView.Execute(oRecord);
//get record
oRecord = oView.Fetch();

do
{
int columnCount = oRecord.FieldCount;
//loop through colums in record
for(int i=1;i<=columnCount;i++)
{
System.Diagnostics.Debug.WriteLine(oRecord.get_StringData(i));

}
oRecord = oView.Fetch();

}while(!(oRecord == null));

//close view
oView.Close();
//flush database buffers as stated in SDK Doc
oDataBase.Commit();

return true;

}
catch(Exception ex)
{
I3NetTrace.Trace_Error(nTopic,ex.Message + ex.StackTrace);
throw;
}
finally
{
//release all, when all go out of scrope, file is released
oView = null;
oDataBase = null;
oInstaller = null;
//as a precaution

}



}
Phil Wilson
2004-05-13 17:52:18 UTC
Permalink
The files are usually in a CAB file in the MSI file, so that is a problem.

If all you want is the version of each file, just do a query on the File
table to get Version (and FileName).
--
Phil Wilson [MVP Windows Installer]
----
Post by Craig Dahlinger
Hey all, I am very new to MSI, but I am trying to do something very simple.
I want to extract the files out of an MSI and get FileVersionInfo oneach
file. I am able to open the database, create view, and get file names for
example, but where are the actual files being stored to extract. I am
assuming they are in binary format so I would have to do a binary
extraction, but I cannot find any examples on the internet or anywhere
please help...
public static bool ExtractMSIInfo(string MSIFile, int iHotFixId)
{
WindowsInstaller.Installer oInstaller;
oInstaller = (WindowsInstaller.Installer)new
WindowsInstaller.InstallerClass();
WindowsInstaller.Database oDataBase = null;
WindowsInstaller.View oView = null;
try
{
//open database
oDataBase =
oInstaller.OpenDatabase(MSIFile,WindowsInstaller.MsiOpenDatabaseMode.msiOpen
Post by Craig Dahlinger
DatabaseModeReadOnly);
//create view
oView = oDataBase.OpenView("SELECT FileName FROM File");
//create record holder
WindowsInstaller.Record oRecord = null;;
//execute query
oView.Execute(oRecord);
//get record
oRecord = oView.Fetch();
do
{
int columnCount = oRecord.FieldCount;
//loop through colums in record
for(int i=1;i<=columnCount;i++)
{
System.Diagnostics.Debug.WriteLine(oRecord.get_StringData(i));
}
oRecord = oView.Fetch();
}while(!(oRecord == null));
//close view
oView.Close();
//flush database buffers as stated in SDK Doc
oDataBase.Commit();
return true;
}
catch(Exception ex)
{
I3NetTrace.Trace_Error(nTopic,ex.Message + ex.StackTrace);
throw;
}
finally
{
//release all, when all go out of scrope, file is released
oView = null;
oDataBase = null;
oInstaller = null;
//as a precaution
}
}
Craig Dahlinger
2004-05-13 19:04:49 UTC
Permalink
I am also trying to get modified date and some other attributes, would like
to extract the file to a temp folfer and load the file into a FileSystemInfo
and get some additional file attributes, any idea on how to do that would be
helpful...
Post by Phil Wilson
The files are usually in a CAB file in the MSI file, so that is a problem.
If all you want is the version of each file, just do a query on the File
table to get Version (and FileName).
--
Phil Wilson [MVP Windows Installer]
----
Post by Craig Dahlinger
Hey all, I am very new to MSI, but I am trying to do something very
simple.
Post by Craig Dahlinger
I want to extract the files out of an MSI and get FileVersionInfo oneach
file. I am able to open the database, create view, and get file names for
example, but where are the actual files being stored to extract. I am
assuming they are in binary format so I would have to do a binary
extraction, but I cannot find any examples on the internet or anywhere
please help...
public static bool ExtractMSIInfo(string MSIFile, int iHotFixId)
{
WindowsInstaller.Installer oInstaller;
oInstaller = (WindowsInstaller.Installer)new
WindowsInstaller.InstallerClass();
WindowsInstaller.Database oDataBase = null;
WindowsInstaller.View oView = null;
try
{
//open database
oDataBase =
oInstaller.OpenDatabase(MSIFile,WindowsInstaller.MsiOpenDatabaseMode.msiOpen
Post by Phil Wilson
Post by Craig Dahlinger
DatabaseModeReadOnly);
//create view
oView = oDataBase.OpenView("SELECT FileName FROM File");
//create record holder
WindowsInstaller.Record oRecord = null;;
//execute query
oView.Execute(oRecord);
//get record
oRecord = oView.Fetch();
do
{
int columnCount = oRecord.FieldCount;
//loop through colums in record
for(int i=1;i<=columnCount;i++)
{
System.Diagnostics.Debug.WriteLine(oRecord.get_StringData(i));
}
oRecord = oView.Fetch();
}while(!(oRecord == null));
//close view
oView.Close();
//flush database buffers as stated in SDK Doc
oDataBase.Commit();
return true;
}
catch(Exception ex)
{
I3NetTrace.Trace_Error(nTopic,ex.Message + ex.StackTrace);
throw;
}
finally
{
//release all, when all go out of scrope, file is released
oView = null;
oDataBase = null;
oInstaller = null;
//as a precaution
}
}
Loading...