寻找在 C# 中进行“净使用”的最佳实践

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 17:20:51  来源:igfitidea点击:

Looking for best practice for doing a "Net Use" in C#

提问by steve_mtl

I'd rather not have to resort to calling the command line.
I'm looking for code that can map/disconnect a drive, while also having exception handling.

我宁愿不必求助于调用命令行。
我正在寻找可以映射/断开驱动器的代码,同时还可以进行异常处理。

Any ideas?

有任何想法吗?

采纳答案by Lars M?hlum

Use P/Invoke and WNetAddConnection2
There should also be some wrappersout there to do some of the grunt work for you.
Google is your friend, as always.

使用 P/Invoke 和WNetAddConnection2
也应该有一些包装器来为你做一些繁重的工作。
谷歌一如既往地是您的朋友。

回答by SitWalkStand

Here is an article for using a class for interfacing to the "map network drive" windows interface: C# Map Network Drive (API)

这是一篇使用类来连接“映射网络驱动器”windows 界面的文章:C# Map Network Drive (API)