1

I'm trying to to write installer for 3rd-party application. The service should be installed and running with arguments. One of the argument it's home folder where the service was installed.

How I can read the folder where the application was installed and pass it to Wix Element: ServiceInstall as arguments.

                <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments="-folder '[INSTALLDIR]\config.txt'>

But [INSTALLDIR] is empty; I suppose it's should be done by using SetProperty and read it but cannot find any references how to do this.

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFiles64Folder">
                <Directory Id="ManufacturerFolder" Name="OEM_XXX">
                    <Directory Id="INSTALLFOLDER" Name="Product  $(var.ProductVersion)">
                        <Directory Id="DirA" />
                        <Directory Id="DirB" Name="SubService">
                            <Directory Id="DirC" Name="ComponentA">
                                <Directory Id="ComponentB" Name="content" />
                            </Directory>
                        </Directory>
                    </Directory>
                </Directory>
            </Directory>
        </Directory>
    </Fragment>
    <Fragment>
        <DirectoryRef Id="DirB">
            <Component Id="Svc1" Guid="b033eb95-ce88-48ac-b40f-6913c5e4b978" Win64="yes">
                <File Source="$(var.SourceDir)\service.exe" />

                    <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments="-folder '???????\config.txt'>

                     <ServiceConfig DelayedAutoStart="no" OnInstall="yes" OnReinstall ="yes" />

                </ServiceInstall>

                <ServiceControl Id="SControl"
                        Stop="both"
                        Remove="uninstall"
                        Name="myservice"
                        Wait="no" />                
            </Component>
        </DirectoryRef>
    </Fragment>

Thanks.

Dmitriy Sosunov
  • 1,075
  • 3
  • 10
  • 25
  • Please show us the surrounding WiX tags - specifically what Directory element is its immediate parent. – Stein Åsmul Feb 25 '19 at 13:38
  • I've updated to show my directories structure – Dmitriy Sosunov Feb 25 '19 at 15:13
  • So the directory is [DirB] (I would assume Arguments="-folder '[DirB]\config.txt'> would work - didn't test - I would uppercase it to DIRB), but why do you need the full path when the config file is in the same folder as the executable? Can't you just get the folder you are running in and then use that on service startup? (haven't done services for a long time). Or maybe put the service configuration in the registry? Just some ideas to throw out there. – Stein Åsmul Feb 25 '19 at 15:41
  • it's 3th-party software. And it require full path to define – Dmitriy Sosunov Feb 25 '19 at 15:55
  • Makes sense, I would do that uppercase [DIRB] then and see if that does the trick. [**Lobbing you some samples**](https://stackoverflow.com/a/25005864/129130). **Mid page**. – Stein Åsmul Feb 25 '19 at 15:59
  • Thanks for your answers. It's really was helpful. I've done what I want. – Dmitriy Sosunov Feb 25 '19 at 22:08

1 Answers1

2

Use [{directoryId} as a reference;

In my case it was

 <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments='-folder "[DirB]config.txt"'>

The full list of available system folder you can find on MSDN:

https://learn.microsoft.com/en-us/windows/desktop/msi/property-reference#system-folder-properties

Sometimes names can confuse you but read description. For example if you would like to define a path to %PROGRAMDATA% you should use [CommonAppDataFolder]

P.S. Build-in variables ends with trailing slash

Dmitriy Sosunov
  • 1,075
  • 3
  • 10
  • 25