Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

stat() of the file located in the shared folder in a windows service program returned error -1 and errno turned out to be 2 (ENOENT).

system where the shared folder exists and system where the service is run are in the same domain. Logged in to service using a valid username/paswd for an account in that domain.

when the same program is run as a EXE stat() returns successfully (0).

Why is the difference in behavior? How to solve this?

share|improve this question

1 Answer 1

Services run from their own context. That context does not include access to any shares that are owned by a particular user. It's not a permission issue, it's a namespace issue.

There are a lot of possible workarounds. One is to run the service under the Network Service account. Another is to have the service replicate the mount itself with an appropriate system call.

The workaround that I prefer is to use a helper process that runs in the user's application context. The helper process can do all file I/O on behalf of the service.

share|improve this answer
    
That context does not include access to any shares that are owned by a particular user. >>shouldn't it work if I log-on the service using a valid username/paswd of a valid account in that domain. –  Girish Dec 29 '11 at 10:45
    
No. It's not a permissions issue, it's a namespace issue. Normally, you wouldn't want the user to be messing with the service's mounts. –  David Schwartz Dec 30 '11 at 2:23
    
I Log-on to the service as a NT AUTHORITY\NETWORK SERVICE and restarted the service. Then granted file in network share permission as in here msdn.microsoft.com/en-us/library/… . both are in same domain. Still I am unable to access the file. Did I miss anything? –  Girish Dec 30 '11 at 10:01
    
found solution to my problem, it was because I was using mapped shared drive. Found solution here stackoverflow.com/questions/3098486/… –  Girish Jan 3 '12 at 4:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.