4

I have a service that I need to be able to write to a network share on another machine using a local account on that machine. To do this I either need to map a network drive that can be seen by the service (logging in as the user the service runs under and mounting the drive does not seem to work), or I need to be able to specify the unc path with a username and password as part of the configuration of my service.

Are either of these things possible?

Jack Ryan
  • 141

4 Answers4

6

the above answer should work....but an easier approach would be to create a local account on both boxes with the same username and password. Then set your service to run under that local account name on ServerA and set ServerB's network share permissions to allow for that local account name on ServerB. Since they are the same username and password it should allow access to the share.

Or better still...make a domain account and use that for both ends.

TheCleaner
  • 33,047
5

You can specify username/password with the net use command.

net use Z: \\Server\SharedFolder passwordGoesHere /USER:userAccountGoesHere /persistent:no
Brandon
  • 2,817
1

What account is the service running under? Is it localsystem or some other account? While the best approach is to use domain user/same user&pass local user for achieving what you want, another alternative is to use the Credential Manager in Windows. You can add a credential for the remote machine while running in the same context the service will run and the authentication subsystem will pick it up automatically. You can easily do this with cmdkey.exe in command prompt for the service account.

Nasko
  • 727
0

Less simple, but another option courtesy of SO.

Kara Marfia
  • 7,882