Windows Service FileSystemWatcher access problems
Posted on 2007-04-10
objective: To have a windows service running on a windows 2003 server (server 1) that listens for file changes and mirrors these changes onto server 2.
private const string SERVER_TWO = "\\\\server\\share$\\";
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
string outFile = SERVER_TWO + e.Name;
catch (Exception ex)
//writes exception to file
implementation: I install this windows service just fine. I have tried running it under the local system, which didn't work obviously. However, I have also tried running it under my account which has full access to the entire network and still no success.
error: System.UnauthorizedAccessException: Access to the path '\\server\share$\subdir\test.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at WebServerSynch.ServiceMain.fileSystemWatcher1_Created(Object sender, FileSystemEventArgs e)
I have searched for this and the solution always seems to be that the account the web service is running under lacks permissions. In this case, that just isn't true. Any suggestions?