views:

472

answers:

2

Hello, I have a windows service developed in VB.net. This Windows Service every night at 8 PM picks a file from copies a file from my C:\ftpDocs to Y:\FtpDocs folder.

Y: is a mapped drive which is \sourceServer\Output files. when I run the same code from VB.net Windows Application instead of windows service it is working absolutely fine. But from the service it is throwing access denied error accessing \sourceServer\Output

It seems windows service runs from C:\windows\system32 for this reason I tried changing the current directory to C:\ftpService( This is the folder where my application is).

To access the map drive I provide a userid and password which is not my windows userid and pwd. Do you think this is the reason why it is not able to access from Windows Service??

If yes, how is it working from windows application. This issue is not going away for the past one month now.

I would really appreciate if you can help me out with this.

Thanks

+3  A: 

What drives are currently mapped is maintained per user -- it'd be a big no-no for me to be able to access files on a share on which you have credentials just because we're both logged on at the same time.

Your service will need to map the share itself using saved credentials of some kind (you could hard code them, if you like, though that's not terribly secure and represents a maintainability burden besides). A good example of how to do this is here -- though, I haven't used this code, I've just read the article.

Dathan
Thanks Dathan, I will surely try this. Thanks again.
rowmark
Thanks Dathan. It worked like a charm.
rowmark
+2  A: 

Typically a Windows service runs under an id whose credentials are not authorized to access files on the network. Try running your windows service under the domain account which can access the network files. Make sure that this account has access to both the network and local folders/files that it will be reading and writing.

Also, you'll want to use the UNC path, not a mapped drive. The mapped drive won't be mounted for the service.

tvanfosson
tvanfosson,I tried UNC Path too. But it didn't help. Next thing is I am planning to get my NetworkID added to the mapped drive folder.
rowmark