简体   繁体   中英

How do I read the msi output folder in a custom boostrapper/installer?

I started a Windows Forms project that in essence it will download several Zip files, un-compress them and run the installer .msi plus it had to be able to ask SQL connection values to be replaced in the Web Site that creates in one of the installer

For example:

  1. Download a Web Proeject installer from http://domain.com/apps/site.zip and install it
  2. Download MS Charts from http://domain.com/apps/mscharts.zip and install it
  3. Ask Server, Database, Username and Password and replace the web.config

This is what I'm trying to do, I know I can use DotNetInstaller or even Wix for this, but both projects are huge and the learning curve is high, so I created my own Installer.

My question is , after I run the Process to install the web setup (a msi that Visual Studio created), how can I get the Full Path of where the user choose to install the site?

This is needed to find out where is the web.config file in order to correctly append the new SQL Server connection values.

The site.msi only returns an integer value using int returnCode = process.ExitCode; never the output path ..

Just thinking out loud

I probably can create a Custom Function on the site.msi to write some value into to Registry and then I can safely read on my custom installer ... is this a viable option?

What can I do in such environment?

My question is, after I run the Process to install the web setup (a msi that Visual Studio created), how can I get the Full Path of where the user choose to install the site?

The usual approach is writing it in the registry:

  • in your Visual Studio setup project go to Registry editor
  • select "Software[Manufacturer]" key under HKEY_LOCAL_MACHINE or under HKEY_CURRENT_USER
  • add a new key under [Manufacturer] and name it

    [ProductName]

  • in this new key add a string entry with this value:

    [TARGETDIR]

This way you MSI will write the installation path in that registry value. Your installer can then read the path from registry.

You could use WMI to search for the MSI installer web.config component of your setup:

  • First you have to identify the component GUID for your web.config component. Open your MSI installer package by using the Microsoft Orca tool (you will find the Orca tool in the Windows 7 SDK).

  • Navigate to the File table . Search for web.config in the FileName column. Remember the ID for the web.config component in the Component_ column.

  • Then navigate to the Component table . Search for your component with the ID found in the file's table.

  • Copy the GUID found in the ComponentId column. This is the component GUID for your web.config file. Now, use the determined Component GUID in the following code:

     ManagementScope scope = new ManagementScope("\\\\\\\\.\\\\ROOT\\\\cimv2"); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SoftwareElement WHERE SoftwareElementID='{YOUR WEB CONFIG GUID}'"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCol = searcher.Get(); foreach(ManagementObject m in queryCol) { Console.Out.WriteLine("Path to web.config: {0}", m["Path"]); } 

By the same token, creating a custom installer action to write the install path to the registry is also a good idea!

Hope, this helps.

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