网络驱动器不提供启动驱动器、网络

2023-09-07 16:00:20 作者:古城白衣少年殇彡

我有一个C#应用程序,它在启动时加载,并记录数据到网络驱动器,它安装为X:

I have a C# application which loads at startup, and logs data to a network drive, which is mounted as X:

当机器第一次启动时,应用程序将引发一个错误X:\不可用。如果我重新启动应用程序,同样的错误。

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

不过,如果我打开Windows资源管理器,双击浏览驱动器,然后我就可以运行该应用程序,它会连接到X:。就好

However, if I open Windows Explorer and double click to browse the drive, I can then run the application and it will connect to X: just fine.

做网络驱动器不能自动初始化启动时,尽管被映射?有没有办法将其设置为自动初始化?

Do network drives not automatically initialise on startup, despite being mapped? Is there a way to set them to initialise automatically?

推荐答案

Ive有完全相同的问题。我不知道是否有更好的方法,在那里,但我已将此添加到我的code访问映射驱动器前。

Ive had the exact same issue. I don't know if there are 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();

这样的驱动器是否可以在启动或不是会始终可用。

That way whether the drive is available at start up or not it will always be available.