Solved

File watcher works on one server UNC path but not for another

Posted on 2014-04-15
3
215 Views
Last Modified: 2015-06-15
I have a windows service that is a setup as a File watcher service. I use the following class to setup my watchers:
    public class Watcher
    {
        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

        public string Directory { get; set; }
        public string Filter { get; set; }

        private Delegate _changeMethod;

        public Delegate ChangeMethod
        {
            get { return _changeMethod; }
            set { _changeMethod = value; }
        }
        public Watcher(string directory, string filter, Delegate invokeMethod)
        {
            this._changeMethod = invokeMethod;
            this.Directory = directory;
            this.Filter = Filter;
            fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes | NotifyFilters.CreationTime
           | NotifyFilters.Security | NotifyFilters.Size;
        }
        public void StartWatch()
        {
            fileSystemWatcher.Filter = this.Filter;
            fileSystemWatcher.Path = this.Directory;
            //fileSystemWatcher.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
            fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
            fileSystemWatcher.EnableRaisingEvents = true;
        }
        void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (_changeMethod != null)
            {
                _changeMethod.DynamicInvoke(sender, e);
            }
        }
    }

Open in new window


I invoke it using the following code:
                Watcher[] w1 = new Watcher[tradingDataSet.tblSpecNewAcct.Rows.Count+1];
                
                for (int i = 0; tradingDataSet.tblSpecNewAcct.Rows.Count - 1 >= i; i++)
                {
                    w1[i] = new Watcher(tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString(), "*.*", mymethod);
                    EventLog.WriteEntry("New Watcher " + tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString());
                    w1[i].StartWatch();
                    EventLog.WriteEntry("Watcher started for " + tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString());
                }

Open in new window


The paths that are retrieved from the database are in the format of :

\\server\folder1\folder2

Open in new window


The service works for our test server but when I switch to the production UNC paths it produces the following error:

The directory name \\server\folder1\folder2 is invalid.

Open in new window


Could this be a permissions problem? The services user credentials is "Network Service" and we have added full permissions for it to the production Folder.

What would make it work on one server path and not for another?
0
Comment
Question by:ButtonDownBobby
  • 2
3 Comments
 

Author Comment

by:ButtonDownBobby
Comment Utility
I tried putting the code into a windows application and it works with the production server but the service still doesn't work. I guess my credentials are valid for the windows form but the service does not seem to be able to access the UNC path.
0
 

Author Comment

by:ButtonDownBobby
Comment Utility
I just changed the "Logon" for the service to use my logon account credentials and the service can access the production UNC path.  This leads me to believe that I have to do something on the production server's user rights for "NETWORK SERVICE". What do I have to do...?
0
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
Comment Utility
you probably won't be able with that (very limited) account

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684272%28v=vs.85%29.aspx

you can create a dedicated account with the needed rights and run the service under that account
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now