简体   繁体   English

如何使用网络使用将samba服务器驱动器映射到C#中的某些本地驱动器?

[英]how to map samba server drive to some local drive in C# using net use?

how to map samba server drive to some local drive in C# using net use ? 如何使用net use将samba服务器驱动器映射到C#中的某些本地驱动器? And how to display them in Windows explorer like window ? 以及如何在Windows资源管理器(如window)中显示它们?

Any code snippet is highly appreciated. 任何代码段均受到高度赞赏。 Thanks in Advance. 提前致谢。

I would recommend creating a batch file which contains the command you want to execute and then call this batch file from your C# application. 我建议创建一个包含要执行的命令的批处理文件,然后从C#应用程序调用该批处理文件。 This ensures if you need to change the net use command it is well encapsulated. 这样可以确保是否需要更改net use命令的封装方式。

myBatchFile.cmd myBatchFile.cmd

net use z: \\server\resource

Application code 应用代码

Process.Start(@"C:\myBatchFile.cmd");

You will need to add this using to your application. 您将需要使用此添加到您的应用程序。

using System.Diagnostics;

See here for more information on Process.Start: 请参阅此处以获取有关Process.Start的更多信息:

Can you expand on "And how to display them in Windows explorer like window ?" 您是否可以展开“以及如何在Windows资源管理器中像窗口一样显示它们?”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM