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
Solved

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

Posted on 2014-04-15
3
282 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
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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 175
Base1 Encode/Decode 3 81
VS2015 Redefinition errors 4 67
object oriented design (python) and documentation tools 2 68
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

766 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