简体   繁体   中英

C# calling and invoking MSI with a Transform MST, with additional switches using Windows Installer

I am attempting to call an MSI to install with a Transform MST, with additional switches using Windows Installer. ultimately I want windows installer to be able to track the install and show accurately its progress on a progress bar.

I have found some snippets of code to get the MSI to install using windows installer, but I'm not having a great lot of luck getting it working.

But if i could get some assistance in figuring out what i need to do would be greatly appreciated. Also where would I put additional switches is the were needed (such as write to a log, allusers=1, etc)?

The following code I have been using is as follows:

private static string appPath = Environment.CurrentDirectory;
private static String msiPath = Path.Combine(appPath, "setup.msi");
private static String mstPath = Path.Combine(appPath, "setup.mst");

Type classType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
Object installerObj = Activator.CreateInstance(classType);
Installer installer = installerObj as Installer;

Database database = Installer.OpenDatabase(msiPath, MsiOpenDatabaseMode.
    msiOpenDatabaseModeTransact);

            database.ApplyTransform(mstPath,
            MsiTransformError.msiTransformErrorViewTransform);
            WindowsInstaller.View viewmst = null;
            string sqlquerymst = string.Format("Select * FROM _TransformView");
            viewmst = database.OpenView(sqlquerymst);
            viewmst.Execute(null);
            database.Commit();
            viewmst.Close();
            string sql = String.Format("Select Property,Value FROM Property");
            WindowsInstaller.View view = database.OpenView(sql);
            view.Execute(null);

I might be misunderstanding what you are trying to do but:

  1. You can install an MSI file + transform by invoking MsiInstallProduct () with a command line that specifies the transform. You don't need to put ALLUSERS anywhere. If you need it in the MSI file then put it in the MSI file, otherwise just add ALLUSERS=1 to the command line. Likewise, specify the path to log on the command line, together with its name.

  2. If you ultimately want to monitor the installation, I'm not sure what your expectations might be, but there is a standard API with defined callback to do this. This kind of thing:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb309215(v=vs.85).aspx

and on somewhere like CodeProject you might find an p/invoke library to call MSI functions from C#, including the callback. Other than that, most MSI files already come with UI so I don't really know what your ultimate goal is.

Why not just use a Process class to call msiexec /I foo.msi TRANSFORMS=foo.mst /qn?

Also if you want to interop with MSI from managed code, the gold standard is the Microsoft.Deployment.WindowsInstaller assembly found in WiX's Deployment Tools Foundation (DTF). It's far similar and elegant then trying to do COM interop. It encapsulates the MSI Win32 API using P/Invoke.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM