views:

162

answers:

2

I created an installer (via WiX) that, as part of the installation, installs a Windows service (written in C#), and starts that Windows service. The service is a FileSystemWatcher and watches for the installation of plug-ins to a specific directory. Originally, it used an environment variable (which pointed to the path I wanted to watch) that was created by the WiX installer, but it was created in a separate directory as shown below:

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="AppFolder" Name="MyApp">
      <Component Id="WatcherService" Guid="[MY GUI ID]">
       <File Id="WatcherEXE" Name="watcher.exe" DiskId="1" Source="../Watcher/bin/Release/Watcher.exe" KeyPath="yes" />
       <ServiceInstall Id="Watcher" Name="PlugInWatcher" DisplayName="Plug-in Watcher" Type="ownProcess" Start="auto" 
                              ErrorControl="normal" Description="Monitors the plug-in folder for new and deleted plug-ins." Account="[SERVICEACCOUNT]" Password="[SERVICEPASSWORD]" />
       <ServiceControl Id="StartWatcherService" Name="PlugInWatcher" Start="install" Wait="no" />
       <ServiceControl Id="StopWatcherService" Name="PlugInWatcher" Stop="both" Wait="yes" Remove="uninstall" />
      </Component>
     </Directory>
    </Directory>

    <Directory Id="CommonAppDataFolder" Name="CommonAppData">
     <Directory Id="MyAppData" Name="MyAppData">
      <Directory Id="PluginAppData" Name="Plugins">
       <Component Id="PluginDir" Guid="[MY GUI ID]">
        <CreateFolder Directory="PluginAppData" />
        <RemoveFolder Id="PluginDir" On="uninstall" />
        <Environment Id="PluginVar" Name="PLUGIN_DIR" Action="set" Permanent="no" System="yes" Value="[PluginAppData]" />
       </Component>
      </Directory>
          </Directory>
        </Directory>
      </Directory>
    </Directory>
</Directory>

Now, I am doing almost the same thing, but the environment variable is now created within the same directory (KeyPath?) like this:

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="AppFolder" Name="MyApp">
      <Component Id="PluginDir" Guid="[MY GUI ID]" KeyPath="yes">
              <Environment Id="PluginVar" Name="PLUGIN_DIR" Action="set" Permanent="no" System="yes" Value="[MyApp]" />
            </Component>

      <Component Id="WatcherService" Guid="[MY GUI ID]">
       <File Id="WatcherEXE" Name="watcher.exe" DiskId="1" Source="../Watcher/bin/Release/Watcher.exe" KeyPath="yes" />
       <ServiceInstall Id="Watcher" Name="PlugInWatcher" DisplayName="Plug-in Watcher" Type="ownProcess" Start="auto" 
                              ErrorControl="normal" Description="Monitors the plug-in folder for new and deleted plug-ins." Account="[SERVICEACCOUNT]" Password="[SERVICEPASSWORD]" />
       <ServiceControl Id="StartWatcherService" Name="PlugInWatcher" Start="install" Wait="no" />
       <ServiceControl Id="StopWatcherService" Name="PlugInWatcher" Stop="both" Wait="yes" Remove="uninstall" />
      </Component>
     </Directory>
    </Directory>
</Directory

The issue is, with the first method, the service worked fine. It would start up, find the path associated with the environment variable, and monitor the directory. With the second method, however, that doesn't happen anymore. The service NEVER sees the environment variable. The variable is created, the service is started, but it never sees it...even if I reboot, etc. It's a really perplexing problem because and makes no sense why.

Any suggestions?

A: 

this might be a stupid idea but have you tried moving the components around? I see in your first piece that you have the component that creates the service first and then the component with the env variable. things should happen in the same order no matter what but I can't see anything wrong with your code otherwise

Gabriel
I actually did try this, and that didn't seem to solve the problem. I was forced to reboot in order to see the environment variable changes which I didn't have to do before.
JasCav
A: 

To answer my own question, it appears that the installer required the system to be restarted in order to see the changes to the environment variables. This is after I had tried stopping and starting the service among other things. I'm not sure why this is because it was working before (without restarting the system).

JasCav