[愚翁专栏]如何把网络共享目录映射为本地驱动器
2006-05-18 20:03
561 查看
如何把网络共享目录映射为本地驱动器 document.title="如何把网络共享目录映射为本地驱动器 - "+document.title
要映射一个网络目录为本地驱动器,需要调用系统DLL的WNetAddConnection2函数来进行添加。
首先,系统函数的申明如下:
using System.Runtime.InteropServices;
[DllImport("mpr.dll", EntryPoint="WNetAddConnection2")]
public static extern uint WNetAddConnection2(
[In] NETRESOURCE lpNetResource,
string lpPassword,
string lpUsername,
uint dwFlags);
[DllImport("Mpr.dll")]
public static extern uint WNetCancelConnection2(
string lpName,
uint dwFlags,
bool fForce);
[StructLayout(LayoutKind.Sequential)]
public class NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
添加映射网络驱动器调用的代码如下:
NETRESOURCE myNetResource = new NETRESOURCE();
myNetResource.dwScope = 2; //2:RESOURCE_GLOBALNET
myNetResource.dwType = 1 ; //1:RESOURCETYPE_ANY
myNetResource.dwDisplayType = 3; //3:RESOURCEDISPLAYTYPE_GENERIC
myNetResource.dwUsage = 1; //1: RESOURCEUSAGE_CONNECTABLE
myNetResource.LocalName = "T:";
myNetResource.RemoteName = yourNetworkPath;
myNetResource.Provider = null;
uint nret = WNetAddConnection2( myNetResource, pwd, username, 0);
注意:如果正确,返回值是0;否则错误。
删除映射网络驱动器调用的代码如下:
uint nret = WNetAddConnection2( yourNetDriveName, 1, true);
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=631309
要映射一个网络目录为本地驱动器,需要调用系统DLL的WNetAddConnection2函数来进行添加。
首先,系统函数的申明如下:
using System.Runtime.InteropServices;
[DllImport("mpr.dll", EntryPoint="WNetAddConnection2")]
public static extern uint WNetAddConnection2(
[In] NETRESOURCE lpNetResource,
string lpPassword,
string lpUsername,
uint dwFlags);
[DllImport("Mpr.dll")]
public static extern uint WNetCancelConnection2(
string lpName,
uint dwFlags,
bool fForce);
[StructLayout(LayoutKind.Sequential)]
public class NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
添加映射网络驱动器调用的代码如下:
NETRESOURCE myNetResource = new NETRESOURCE();
myNetResource.dwScope = 2; //2:RESOURCE_GLOBALNET
myNetResource.dwType = 1 ; //1:RESOURCETYPE_ANY
myNetResource.dwDisplayType = 3; //3:RESOURCEDISPLAYTYPE_GENERIC
myNetResource.dwUsage = 1; //1: RESOURCEUSAGE_CONNECTABLE
myNetResource.LocalName = "T:";
myNetResource.RemoteName = yourNetworkPath;
myNetResource.Provider = null;
uint nret = WNetAddConnection2( myNetResource, pwd, username, 0);
注意:如果正确,返回值是0;否则错误。
删除映射网络驱动器调用的代码如下:
uint nret = WNetAddConnection2( yourNetDriveName, 1, true);
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=631309
相关文章推荐
- [愚翁专栏]如何把网络共享目录映射为本地驱动器(续)
- 如何把网络共享目录映射为本地驱动器
- 如何把网络共享目录映射为本地驱动器
- 如何把网络共享目录映射为本地驱动器(续)
- winform把网络共享目录映射为本地驱动器&局域网内copy文件&设置文件夹共享
- 转:IIS虚拟目录实现与文件服务器网络驱动器映射共享
- Windows下如何将服务器目录映射到本地驱动器
- WIN10映射ubuntu1604共享目录(网络驱动器)
- IIS虚拟目录实现与文件服务器网络驱动器映射共享
- IIS虚拟目录实现与文件服务器网络驱动器映射共享
- 如何将网络上的共享文件映射到本地
- C#里将其他共享目录映射为本地盘符的方法
- 如何让域中的计算机开机自动映射网络上的共享文件夹
- 计算机网络10问之6 如何将网络共享文件夹映射到你的计算机
- 如何映射网络驱动器
- C#里将其他共享目录映射为本地盘符的方法
- 把其它地址的共享目录映射到本地
- .NET 在网络上创建映射磁盘 (在服务器a上创建服务器b的共享磁盘并访问目录)
- NetDrive将网络目录映射为本地磁盘
- 如何映射基于用户所在组的网络驱动器