2009-10-01 120 views
1

我创建了一个安装程序(通过WiX),作为安装的一部分,安装Windows服务(用C#编写),并启动该Windows服务。该服务是一个FileSystemWatcher并监视插件安装到特定目录。最初,它使用的环境变量(指着我想看的路径),这是由维克斯安装程序创建的,但它是在一个单独的目录创建如下图所示:服务无法查看环境变量

<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> 

现在,我做几乎同样的事情,但环境变量现在相同的目录(?的keyPath)这样的中创建:

<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 

的问题是,与第一种方法,服务工作的罚款。它会启动,找到与环境变量关联的路径,并监视目录。然而,第二种方法不会再发生。该服务从不看到环境变量。该变量已创建,服务已启动,但它从未看到它,即使我重新启动等。这是一个非常令人困惑的问题,因为并没有意义为什么。

有什么建议吗?

回答

0

要回答我的问题,看来该安装程序所需的系统才能看到重新启动对环境变量的更改。这是我尝试停止并开始其他服务之后的服务。我不确定为什么这是因为它在以前工作(无需重新启动系统)。

0

这可能是一个愚蠢的想法,但你有没有尝试移动组件? 我在你的第一篇文章中看到,你有组件首先创建服务,然后使用env变量创建组件。 事情以相同的顺序发生,不管什么,但我看不出什么错与您的代码,否则

+0

我其实确实尝试过这种方式,而这似乎并没有解决问题。我被迫重新启动,以便查看我以前不必执行的环境变量更改。 – JasCav 2009-10-28 14:57:02