Specifying Username/Pass as part of a UNC path or map network drives for a windows service

28,584

Solution 1

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.

Solution 2

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

net use Z: \\Server\SharedFolder passwordGoesHere /USER:userAccountGoesHere /persistent:no

Solution 3

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.

Share:
28,584
Jack Ryan
Author by

Jack Ryan

Updated on September 17, 2022

Comments

  • Jack Ryan
    Jack Ryan almost 2 years

    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?

  • user13846
    user13846 almost 15 years
    This method is better as it does not expose your password wherever your script lives.
  • Jack Ryan
    Jack Ryan almost 15 years
    How do I go about doing this for my service through. It still doesnt add the share for the service.
  • Jack Ryan
    Jack Ryan almost 15 years
    will this work for a domain account on one end and a local account on the other end? I ask because I have a few machines on the same domain that would benefit from the domain account. but one that is outside the domain and so would need a local account.
  • kralyk
    kralyk almost 15 years
    it should...as long as the account login id and password are the same on both ends (sans the domain part)
  • aloo
    aloo about 14 years
    When you say "the above answer should work" which answer are you referring to? This is (currently) the top rated answer, so there is no answer "above" it.
  • kralyk
    kralyk almost 14 years
    Rjmunro - I was referring to the one by routeNpingme. Notice his comment is timestamped before mine. That was the one I was referring to.