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?