1

I write a windows service with .net core 3.1. this service should access to NFS drive but throw the following Exception.

System.IO.DirectoryNotFoundException: Could not find a part of the path 'Z:...\sample.txt'.

I have installed this service with the same user that I logged on to the system (windows server). Also, I wrote a Console application for the test, the console application can access to the NFS drive.

Why I can access by the console and the same user but in windows service, I can not access the NFS drive.

Mohammad Akbari
  • 3,809
  • 5
  • 31
  • 58
  • Because your service doesn't have an interactive logon where network drives (like Z:\) are mapped. Have your service access the actual unc path instead. – Filburt Sep 16 '20 at 16:50
  • Are you running as an Admin in VS. VS doesn't automatically give Admin rights. Code will run outside VS. You can create a shortcut to VS. Then start VS by right click shortcut and select Run As Admin. – jdweng Sep 16 '20 at 16:53

1 Answers1

0

Makes sense as you can see here: Map a network drive to be used by a service and https://superuser.com/questions/650025/how-to-access-mapped-directory-from-a-windows-service

Why?

persistent drive mappings are only restored on an interactive logon, which services typically don't perform.

My suggestion, go with the symbolic link. Seems the simpler of solutions

mklink /D C:\myLink \\127.0.0.1\c$
Athanasios Kataras
  • 20,791
  • 3
  • 24
  • 45