We help IT Professionals succeed at work.

Windows Installer CompanyName property

daveokst
daveokst asked
on
451 Views
Last Modified: 2013-11-26
We have an app that uses a database.  During the Windows Installer process, there is a form we added that pre-populates the Organization Name [COMPANYNAME].  How can I get that value from the windows installer into our database after or during installation?
Comment
Watch Question

icr

Commented:
What installer are you using? Does it allow you to run arbitrary pieces of code/programs at different points during the install process? Some do.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you for the responses, but for some reason I am not able to perform actions as it seems the location or required assemblies aren't ready for use.  I have tried two different approaches using a custom action.  My custom action calls into the project output dll by overriding the Commit()

   [RunInstaller(true)]
   public class InstallerHandle : System.Configuration.Install.Installer
   {
      public override void Install(IDictionary savedState)
      {
         base.Install(savedState);
      }

      public override void Commit(IDictionary savedState)
      {
         base.Commit(savedState);
      }

      public override void Rollback(IDictionary savedState)
      {
         base.Rollback(savedState);
      }

      public override void Uninstall(IDictionary savedState)
      {
         base.Uninstall(savedState);
      }

   }

First Attempt:
In the commit override, I try to do something like save a file to the application root, but the file never gets saved there.  This file is supposed to be a simple XML file with company name.

Second Attempt:
I attempt to save company name to an embedded mode Firebird database which powers much of the application after install (this is where I want company name to really go), but this fails because none of the supporting files, to include the App.config which has the connection string, seem to exist yet.

Custom Action seems the way to go, but also seems to prevent any modification of the application by choices made in the installer.

I am using the .Net Setup and Deployment Windows Installer.

Author

Commented:
Thanks for pointing me in the right direction... as it turns out I went with the First Attempt above, and was able to save the file to the folder location as defined by another property I passed in through the Commit Custom Action... so it all ended up looking like this:

Custom Action Properties:
/TargetDirectory="[TARGETDIR]\" /CompanyName="[COMPANYNAME]"

Code:

   [RunInstaller(true)]
   public class InstallerHandle : System.Configuration.Install.Installer
   {
      private const string COMPANYNAME_KEY = "CompanyName";
      private const string TARGETDIR_KEY = "TargetDirectory";

      public override void Install(IDictionary savedState)
      {
         base.Install(savedState);
      }

      public override void Commit(IDictionary savedState)
      {
         base.Commit(savedState);
         
         //Debugger.Launch();
         //Debugger.Break();

         if (!Context.Parameters.ContainsKey(COMPANYNAME_KEY))
            throw new Exception(string.Format("The key {0} was not found", COMPANYNAME_KEY));

         if (!Context.Parameters.ContainsKey(TARGETDIR_KEY))
            throw new Exception(string.Format("The key {0} was not found", TARGETDIR_KEY));

         Company c = new Company();
         c.CompanyName = Context.Parameters[COMPANYNAME_KEY];
         
         XmlStorage<Company> CompanyName = new XmlStorage<Company>(Context.Parameters[TARGETDIR_KEY]);
         CompanyName.Data = c;
         CompanyName.Save();

      }

      public override void Rollback(IDictionary savedState)
      {
         base.Rollback(savedState);
      }

      public override void Uninstall(IDictionary savedState)
      {
         base.Uninstall(savedState);
      }

      protected override void OnAfterInstall(IDictionary savedState)
      {
         base.OnAfterInstall(savedState);
      }
   }

Two things to point out... use Debugger.Launch(); to debug.  Also, there is a bug in the way custom properties are passed.  Phil Wilson talks about this on a few forums, but the solution is to use quotation marks and be careful with the use of the backslash.  I had to even reorder the keys to TargetDirectory came before CompanyName, otherwise the install will crash with a weird filenotfound exception if the user types in a company name with spaces and other characters like a comma or period. as in "My Company, LLC."
I was not aware of those "undocumented features." :o)

Thanks for the heads up.  I'll add this to my Knowledge Base for future reference.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.