Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-15
3
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:ButtonDownBobby
ID: 40001841
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
ID: 40002042
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 27

Accepted Solution

by:
skullnobrains earned 1500 total points
ID: 40006646
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

604 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