2
Answers

Copying files from one network path to another network path in Window Service

Photo of rahul rastogi

rahul rastogi

16y
9.6k
1
Hi,

I want to copy files from one network path to another network path through windows serivce.

I am impersonating the user but it works only for one network path at a time. If I try to impersonate another user the first one becomes invalid.

Is there a way through which we can impersonate two users simulateneously.

I know other way is that I copy file from source network path to local system and then copy it from local system to destination network path i.e impersonating one user at a time but there are other things in my code which will make this too complicated.

I would really appreciate if anybody can help me on this.


Regards,
Rahul Rastogi

Answers (2)

0
Photo of David Johnson
NA 26 0 16y

You can fix this with one of several solutions

Have your Sys Admin set up a service user and have them ONLY grant access to the two paths  so domain\ServiceUser has access to \\Server1\share and \\Server2\share then run the service as that user

Second you can run the service as Local System Account and grant the machine access to both paths

Third Have the Service run on Server1 and use a filesystemwatcher to activate the service and then you ONLY have to grant access to server 2

FileSystemWatcher MUST run on the server it is monitoring to run successfully and reliabley

These are just a couple of the ways to Fix this

 

 

 

0
Photo of Scott Lysle
NA 28.5k 14.4m 16y
It might not be the party-line way to go but I found the easiest way to handle this particular issue is to set up a virtual directory pointing to the location you want the service to access, and then setting up the permissions to give the windows service account credentials read and/or write access to that virtual directory.