简体   繁体   中英

Windows Service cannot access network location (UNC) Path

I have a windows service that polls a folder continuously for new files.For local directories this works fine.But when it comes to UNC Paths on another system in the same.network,the service cannot access the folder it seems.I have refereed to this post https://serverfault.com/a/881272 ; it states that i need to run the service as the currently logged in user.How im i supposed to do that?

The path i wish to monitor using the service is

\DESKTOP-PC\Users\me\myfolder

Please advice

UPDATE:

I have developed the service using topshelf.I want to poll a folder on another local machine in the same.network.I go to.network places,double click on the computername,it asks for credentials,i enter the username and password of the remote computer i get access to the files on the system for that user(in explorer).

Now when i set the service to run as the local machine user under this machine,it cannot access the remote UNC Path that is accessible using explorer.I have tried installing it as the remote machine user,but it fails.

myService.exe install -username:DESKTOP-REMOTE\myname -password:mypassword
  1. Open the Control Panel > Administrative Tools > Services window on your Windows server.
  2. Stop your windows service.
  3. Open the Properties > Log On dialog.
  4. Change the service user account to the target user account.
  5. Start your service.

在此输入图像描述

If you are developing the service in Visual Studio, and want to emulate a different account you can also press shift + right mouse click on devenv.exe and click on "run as different user".

Also make sure you are specifying the full path to the folder and that the account you use has full rights to the folder.

If you try to run your service under the desktop-remote\\myname account you probably will fail. The local machine only likes accounts belonging to itself.

What I would do is to turn it around. Make the remote computer share a folder for your machine to poll. That way the remote machine has control over which data it is publishing, just like an object has its properties to private or public . If you are ok with having anyone who knows the address \\\\desktop-remote\\my-not-so-secret-folder\\ being able to read it, set it so anyone can read. If you are more secretive, suffix the folder with $ like so: \\\\desktop-remote\\my-secret-folder$ . Now it is not visble but still reachable.
You can also create a special account that has access to said folder.

Then you let your service run any account (with network access) of your choosing on your local machine. Let it try to connect to the remote folder with the special account.

(I have learned, the hard way, that reading a shared folder is slightly different between machines without domain and machines in a domain; the anyone-can-read does not work. At least in WindowsXP it was that way. I have since then not have the need to share a folder.)

HTH

I was facing this problem with my UNC storage in the Azure cloud. What worked is setting up the credentials in the windows credentials manager:

windows credential manager

You can get the connection string from the Azure portal.

This resolved our problem.

When you set the service to run as the local system account, it cannot access the remote UNC Path that is accessible using explorer with local machine account.

Simply because the explorer manages logged on user credentials, so, you have added UNC path credentials to the LOGGED user only.

When you change it to Local System Account, the user credentials to the share is not stored.

Try to create a local user without password expiration and then enable it access to the Share.

All you will need to do is to setup windows service with this new account registered.

安全

You can have a look at Impersonation. Also, if the service is running as a localuser, then it would help to create the same user with similar password on the machine where the folder resides.

Have a look here (the OP in this post is experiencing the same issue and he/she has given the shared folder “Everyone access to full control”.

https://serverfault.com/questions/177139/windows-service-cant-access-network-share

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM