如何使用C#映射驱动器? [英] How to Map a Drive using C#?
本文介绍了如何使用C#映射驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用C#我如何映射网络驱动器。我不想使用 NET USE
或任何第三方的API。
How can I map a network drive using C#. I don't want to use net use
or any third party API.
听说了C#code UNC路径,但不太清楚如何去做。
Heard about UNC paths in C# code but not quite sure how to go about it.
推荐答案
使用的 WnetAddConnection
在本机可用的功能 MPR.DLL
。
您将不得不写的P / Invoke签名和结构,以调用通过对非托管函数。你可以找到P上的资源/调用在 pinvoke.net 。
You will have to write the P/Invoke signatures and structures to call through to the unmanaged function. You can find resources on P/Invoke on pinvoke.net.
这是的签名 WNetAddConnection2
上pinvoke.net :
This is the signature for WNetAddConnection2
on pinvoke.net:
[DllImport("mpr.dll")]
public static extern int WNetAddConnection2(
ref NETRESOURCE netResource,
string password,
string username,
int flags);
这篇关于如何使用C#映射驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文