我創建了一個安裝程序(通過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
的問題是,與第一種方法,服務工作的罰款。它會啓動,找到與環境變量關聯的路徑,並監視目錄。然而,第二種方法不會再發生。該服務從不看到環境變量。該變量已創建,服務已啓動,但它從未看到它,即使我重新啓動等。這是一個非常令人困惑的問題,因爲並沒有意義爲什麼。
有什麼建議嗎?
我其實確實嘗試過這種方式,而這似乎並沒有解決問題。我被迫重新啓動,以便查看我以前不必執行的環境變量更改。 – JasCav 2009-10-28 14:57:02