Mohammad Akbari
Mohammad Akbari

Reputation: 4776

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.

Upvotes: 1

Views: 1930

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26450

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$

Upvotes: 1

Related Questions