Results 1 to 9 of 9

Thread: Changing config infor in a program during the installation

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Changing config infor in a program during the installation

    Hi guys, this is a tough one.

    I'm trying to ask the user to input data that I will use to input in the configuration file during the installation process.

    So what I did was to create a small test application. In the first form (app1), I simply print out the contents of the configuration file.

    Then I added a new project to that one (app2), and in that project, I created a simple interface to input one parameter from the user and write that parameter to the configuration file. The line of code that i used to write to the configuration file is: WriteDoc.Save(@"App.config");

    Then I created the installation program, added the primary output and source content of both app1 and app2. After it was created, I went to the custom action of the set up, and added the project app2 in the install custom action. I selected the property installer class to be false. This will run the application during the set up installation.

    All of this is working properly. The app2 is running during the installation. However one problem. When I'm writing to the file App.config, it's not reading the file from the directory that the user selected during the installation process but rather from this directory: c:/windows/system32. I guess this is some default directory. I do not quite understand it.

    So app2 is supposed to update the configuration file from app1. Both of these source files are being copied to the same directory that the user selects. How could I read that directory that the user selects during the installation setup program? In other words, app2 must write to App.Config which is located in:

    DirectoryUserSelected/App.Config

    How could I find out this directory that the user selected so I could specify it in app2 as the path to write to?

    Is this even possible???

    Jennifer

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Changing config infor in a program during the installation

    In your example, when does App2 start?

  3. #3

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Changing config infor in a program during the installation

    App2 starts when the applications are installing. After the user selects the path, and clicks: INSTALL, midway during this installation, App2 runs and the installations does not finish until something is inputted in App2.

    However, since App2 is a normal application, you could run App2 after since I'm installing both App1 and App2 in the directory. When I run App2 and try to change something in the config file, it works properly and this is since the root directory is in the same directory as App1 with the config file. This is fine. But during the installation, it apparently is not in the same directory as App1 and thus I have to find some way to read the directory that the user selected.

    I hope this explains it better.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Changing config infor in a program during the installation

    Since App2 starts after the path is inputted you could pass the path as a command line parameter to when you start it?

  5. #5

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Changing config infor in a program during the installation

    And how do I do this? remember that the path is being inputted from the set up program. I never did this before. How do I do this? - jennifer

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Changing config infor in a program during the installation

    You'll have to bear with me, I've never deployed a .NET app :-(

    When you start App2 from the installer. At that point you must have the install path, in the installer app. Just pass the path, as an argument, when you Process.Start App2, or however you are doing it. And then in App2 you can read the path in your startup method.

    Code:
    static void Main(string[] Args)
      // Args = install path
    Would that work? Or is it more complicated?

  7. #7

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Changing config infor in a program during the installation

    I'm wondering if this will work. You see there's three applications running here. App1, App2 and the setup. If i get the path that App2 is at that moment, I know that path. It's c:\system32.... What I want is the path from the setup program that the user selects.

    I understand what you're saying about passing the path. That is my main question. When the user selects this path, how could I pass it to App2. Once I could read it in App2, I'm home free, I could now write to the file. how could I pass that path since the setup application is not really a program I could modify right?

    Jennifer

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Changing config infor in a program during the installation

    Oh - How exactly did you create the installer?

  9. #9

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Changing config infor in a program during the installation

    Ok. First I created the main app1. Then I went to File --> Add Project --> New project --> and that's where I created app2 which contains a simple form to input a value from the user to update the configuration file.

    To create the installer,

    File -> Add project -> new project -> choose 'setup and deployment' and choose 'setup wizard'. click next, choose 'create setup for a window application' -> next -> select the primary output and the source files next next finish.

    At this point, if you look in your solution explorer you will see three projects, app1, app2 and the setup.

    Right click on the setup in the solution explorer -> view -> custom actions.

    The custom action interface will open.

    you will see install as a folder there. right cliick on INSTALL folder -> add custom action -> select the primary output from app2. It will then display itself as a child node to INSTALL. Select the child node of the primary output of app2, and go to the properties.

    Here in the properties of the primary output of app2, you will see an option INSTALLER CLASS. This should be set to true by default, set it to FALSE. This is what will bring up the app2 during the installation.

    Next go to the solution explorer, build app1, app2 and setup separately in that order. Then go to the visual studio directory and in the setup folder, go in the debug folder and you will see a setup.msi file. This is the installation file. Double click and the installer should run.

    Jennifer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width