okerupt
asked on
Windows Service FileSystemWatcher access problems
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.
current implementation:
private const string SERVER_TWO = "\\\\server\\share$\\";
private void fileSystemWatcher1_Created (object sender, System.IO.FileSystemEventA rgs e)
{
System.Threading.Thread.Sl eep(5000);
try
{
string outFile = SERVER_TWO + e.Name;
if (System.IO.File.Exists(out File))
System.IO.File.Delete(outF ile);
System.IO.File.Copy(e.Full Path, outFile);
}
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.UnauthorizedAccessE xception: Access to the path '\\server\share$\subdir\te st.txt' is denied.
at System.IO.__Error.WinIOErr or(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCop y(String sourceFileName, String destFileName, Boolean overwrite)
at WebServerSynch.ServiceMain .fileSyste mWatcher1_ Created(Ob ject 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?
current implementation:
private const string SERVER_TWO = "\\\\server\\share$\\";
private void fileSystemWatcher1_Created
{
System.Threading.Thread.Sl
try
{
string outFile = SERVER_TWO + e.Name;
if (System.IO.File.Exists(out
System.IO.File.Delete(outF
System.IO.File.Copy(e.Full
}
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.UnauthorizedAccessE
at System.IO.__Error.WinIOErr
at System.IO.File.InternalCop
at WebServerSynch.ServiceMain
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?
When I tested it on my network, I wrote a quick demo;
System.IO.File.Copy(@"C:\t est.bmp",@ "\\10.0.0. 6\c$\test. bmp");
And it worked without a problem... can you access this "directory" as you wrote it \\server\share$\subdir\, via explorer for instance? If so, then I'm curious what account your service is running under.
System.IO.File.Copy(@"C:\t
And it worked without a problem... can you access this "directory" as you wrote it \\server\share$\subdir\, via explorer for instance? If so, then I'm curious what account your service is running under.
ASKER
I have tried running it under the local system account, 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.
Also, yes I can access this \\server\share$\subdirecto ry just fine in windows explorer with my user account. I ran the same code as a windows program and it worked fine so something is very strange here.
Also, yes I can access this \\server\share$\subdirecto
ASKER
Also, I add files to these server shares from my local computer all the time so my account having access is pretty much unquestionable.
Does the release compiled version have this problem? Or while you're debugging?
ASKER
This is the released version. Also, I am not aware of how to debug a windows service using the visual studio 2005 IDE. When I try, it gives me the "has to be installed using installutil" error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Connect on SERVER_TWO computer and check that you have write access to both the share itself AND the underlying directory. In order to perform the check start the Administrative Tools / Computer Mangement program. Select the System Tools / Shared Folders / Shares tree node on the left. In the right pane, tight click the target share and check last two panes (Share Permissions AND Security). You should have write access on both.
Another easy interactive way to perform the test is to map the share in Windows Explorer (Tools / Map network drive menu item) then to try to drag an drop a file in the newly mapped share. If the drop succeed, you might assume you have correct permissions.
Can you proceed please and acknowledge your results.