Search code examples
c#.net-corewindows-servicesnfs

Accessing to NFS drive from windows service in C#


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.


Solution

  • 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$