Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting the installation directory from an installer

Getting the installation directory from an installer

Scheduled Pinned Locked Moved C#
csharpvisual-studiowinformsquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G Ringbom
    wrote on last edited by
    #1

    I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.

    C M G 3 Replies Last reply
    0
    • G G Ringbom

      I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.

      C Offline
      C Offline
      Carsten Zeumer
      wrote on last edited by
      #2

      Check out the MsiGetProductInfo[^] function in the msi.dll . The INSTALLPROPERTY_INSTALLLOCATION property returnes the installation path. Sorry that I do not have any samples on how to do it in .NET and C#. But it should be fairly straight forward using pInvoke. /cadi 24 hours is not enough

      1 Reply Last reply
      0
      • G G Ringbom

        I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        You could create a class library for the custom action of writing the installation path into your config file. Inside your InstallerClass you can use reflection to get the location the custom action is executed from (Assembly.GetExecutingAssembly().Location). This usually would be in the directory your service has been installed to. Regards, mav

        1 Reply Last reply
        0
        • G G Ringbom

          I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.

          G Offline
          G Offline
          G Ringbom
          wrote on last edited by
          #4

          I managed to find a solution. I had a custom action in the installation to handle the Installer classes I had in my projects and there is a propery for a custom action called CustomActionData there. By setting the value of that parameter to /installdir="[TARGETDIR]\" I could get the installation directory in my Installer class with this code: this.Context.Parameters["installdir"]. And that was all I needed. Took a while to find all parts of this solution and puzzle it together. I found one part of this solution at a time. Nowhere was it explained all the way. Thanks everybody for trying to help me!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups