Recently, a Windows Service was developed to synchronize file synchronization between shared directories. consider that in the copy process, if the network suddenly can not access, causing the file copy is incomplete, decisively abandon the copy method of. Net, and use the xcopy command under DOS command.
Well..... Just do what you say.
xcopy program validation, development, debugging (two shared directories built from a PC) .... Half a day, all done. It seems that things are going too well .....
Since local debugging is no problem, deploy to a test environment. All right... Here's the problem.
Sync two shared directories, incredibly failed! View the log, Xcopy's exit code exitcode=4, which means the path is incorrect.
Strange.... There's no reason ... On the test server, it is accessible and can be read and written in a \\IP\\ShareFolder manner.
Run the xcopy command in the cmd window just after the failed synchronization, actually succeeded ...
As you can see, the Windows service does not have permission to access the share.
Google..... Google....... Find a way to add permissions.
Reference Links:
http://stackoverflow.com/questions/9905281/ How-to-access-to-a-shared-resource-with-a-windows-service-using-local-system-use
The steps are as follows:
1) First find a user with shared directory read and Write permissions
2) in the properties of Windows service, select the Login tab, under this user, to a user who has read and write access to the shared directory.
3) Click OK to restart the service.
All right, with an excited heart, restart, Resync, continue to fail ......
Not to say to the service to add a user on it ... Cheat paper .....
Continue Google ... Google.... Google..................
Have to say, StackOverflow above Daniel is more ...
Using the NET Use command to create a link to a share
Usage: Net use \\ServerIP\\ShareFolder password/user:user
No more nonsense, just try it ...
Command completed successfully .... With excitement, restart the service ..... Synchronization success!!!
Reprinted from Http://www.bkjia.com/C_jc/822288.html