Network drive not available at startup

I have a C # application that loads on startup and logs data to a network drive that installs as X:

When the machine first boots up, the application throws an error message that X: \ is not available. If I restart the application then the same error.

However, if I open Windows Explorer and double-click to view the drive, I can launch the application and connect to X: just fine.

Aren't network drives automatically initialized at startup, despite being mapped? Is there a way to automatically initialize them?

+3


source to share


2 answers


I had the same problem. I don't know if there are any better methods out there, but I added this to my code before accessing the mapped drive.

Process mapDrive = new Process();
mapDrive.StartInfo.FileName = "net.exe";
mapDrive.StartInfo.Arguments = @"use c: \\server\share";
mapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
mapDrive.Start();

      



Thus, whether the disk is available at startup or not, it will always be available.

+2


source


See How to access a mapped network drive here on SO for a list of things to check. I am assuming that either the disk does not exist for your user or there is a problem accessing it. Another element to check is the order in which you invoke impersonation , assuming you do.



According to Can't access files on a mapped drive from a Windows service , you shouldn't be doing this at all. See Microsoft references cited in the accepted answer.

0


source







All Articles