如何使用C#映射驱动器?

Sim*_*ons 7 .net c#

如何使用C#映射网络驱动器.我不想使用net use或任何第三方API.

听说过C#代码中的UNC路径,但不太清楚如何去做.

fle*_*her 9

使用WnetAddConnection本机中可用的功能mpr.dll.

您必须编写P/Invoke签名和结构以调用非托管函数.您可以在pinvoke.net上找到P/Invoke上的资源.

这是pinvoke.net上的签名WNetAddConnection2:

[DllImport("mpr.dll")]    
public static extern int WNetAddConnection2(
   ref NETRESOURCE netResource,
   string password, 
   string username, 
   int flags);
Run Code Online (Sandbox Code Playgroud)