Search code examples
.netwindows-servicesfilesystemwatcher

How to use FileSystemWatcher in Windows service


If I use FileSystemWatcher for monitoring files created on network share in console application, everything works fine. But if I move this simple code into Windows service, it does not work. I tried lot of various things: Checking access permissions of given folder, trying to run service as LocalService, LocalSystem, Network service and administrative domain user account. I also tried impersonation of code using SimpleImpersonation library. Nothing worked. Any suggestions?


Solution

  • Problem was in account, under which was service started. For FileSystemWatcher to correctly watch changes on Samba network share, I used Administrator account from domain.