Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 889
techno Avatar asked Dec 14 '22 15:12

techno


2 Answers

  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.

enter image description here

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.

like image 177
Mehdi Ibrahim Avatar answered Dec 27 '22 17:12

Mehdi Ibrahim


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

like image 30
LosManos Avatar answered Dec 27 '22 17:12

LosManos