getting location of executing setup.exe using custom actions

Posted on 2009-04-18
Last Modified: 2013-11-14

VS 2005 C#

I am using a installer class as I need a custom action that will read in a xml config file.

So when the user double clicks the setup, there will be a config.xml file in the same folder. I would like to read in this config.xml file on install event. The folder will contain setup.exe and config.xml

However, the code gives me the location of where the custom action has been installed to.

What I am looking for is this.
1) The user will download a zip file that will contain a folder with the setup.exe and config.xml.
2) The user can unzip this anywhere on their computer. i.e. desktop.
3) They double click the setup.exe and I would like to get the location of where they have unzipped. Which would be the folder with the setup.exe and config.xml.
4) Its that config.xml I would like to read in.

The config.xml is not packaged in the setup.exe. This is because the client would like to make some changes to the application after the setup.exe has been created.

Actually just to give further information. I give the setup.exe to the client plus a config.xml file, they will zip this up and make it downloadable form their website, so they customers can use it. However, if they want to change something like IP address that the application uses, they can use this config file and get the customers to download again. This is because they don't want to have another setup.exe created.

So that is why I am using the step above,

Many thanks,
protected override void OnAfterInstall(System.Collections.IDictionary savedState)


     // Create a data table to hold the contents of the xml file

     DataTable dt = new DataTable();

     // Test to see if it is looking for the config in the right location


     // Read in





Open in new window

Question by:steve1_rm
    LVL 3

    Expert Comment

    You should add the config file to your install project. Then You parse the install path to the installer class:

        public partial class Installer1 : Installer
            public Installer1()
            public override void Install(IDictionary stateSaver)
                catch (Exception e) { MessageBox.Show(e.Message); }
    Context.Parameters["targetdir"].ToString()  contains your path - remember to  add your project to the Custom Action in the install project. And remember to set the property CustomActionData to
    That should do the trick.
    p.s. Put your install logic in a local method fx. DoInstall

    Author Comment


    Thanks for the advice.

    However, the main problem is. Is that I cannot include the config.xml in the setup package. The config.xml is there so that our client can modify some values. If the config.xml is included. Then they cannot do this.

    This was what I need to do and our client has requested this. For example there is an server IP address that the application uses. Which is stored in the config.xml. The client doesn't want us to create another setup.exe, as they don't want to wait for us to do one. They just want to change things on the fly. So they make the change to the config file. And their customers will download the zip file that will contain the ordinal setup with the modified config file.

    When they double click to install the custom action will read in the config.xml file. However, I am having a problem, as the customer could download and unzip anywhere on their computer.  So that is the main problem is getting the location of the config.xml that is contained in the same zipped folder at the setup.

    Many thanks for anymore suggestions,

    LVL 40

    Accepted Solution

    You probably can read property SOURCEDIR - see
    LVL 40

    Expert Comment

    by:Vadim Rapp
    ID 24184751 is the answer.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    One of the most frequently asked questions on EE in the "Windows Installer" zone is how to eliminate self-triggered installation of some product.  The problem occurs when, suddenly, whenever a certain application is launched, or even when a folder i…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now