Powershell脚本运行System.IO.FileSystemWatcher作为Windows服务

我需要一个FileWatcher脚本来检测新文件并执行另一个PowerShell脚本,如果find文件。 此第二个PS脚本的目标目录将文件输出到目录以P:挂载的UNC装载。 UNC挂载实际上是一台Linux机器的SMB共享。 该Linux机器托pipe一个SMB服务,授予一个Linux用户的权限。 该Linux用户有适当的权利来创build和修改SMB目录中的文件。

我可以得到filewatcher脚本执行行动完全罚款,如果我在login时在实时窗口中运行脚本。

我无法让filewatcher脚本作为Windows服务运行,并在System.IO.FileSystemWatcher检测到新文件后正确执行命令。

我使用winsw.exe格式来创buildWindows服务。 当我作为SYSTEM用户运行这个…什么都不是。 当我以自己的方式运行服务时,成功在实时窗口中运行它的同一个用户什么都没有。

这是winsw.xml

<service> <id>StartWatchingFiles</id> <name>Start Watching Files</name> <description>This is used to watch files.</description> <executable>PowerShell.exe</executable> <logmode>reset</logmode> <arguments>-ExecutionPolicy Bypass -File "C:\scripts\StartWatching.ps1"</arguments> </service> 

运行之后,将生成文件,并且观察程序脚本不会触发PS脚本以响应新检测到的文件。