【探索发现】.NET 创建虚拟磁盘
呵呵 cnblogs建博第一天分享一下自己的心得
[DllImport("Kernel32.dll")]
public static extern bool DefineDosDevice(int dwFlags, string lpDeviceName, string lpTargetPath);
/// <summary>
/// 加载虚拟磁盘
/// </summary>
/// <param name="strDeviceName">盘符</param>
/// <param name="strTargetPath">映射的文件夹</param>
/// <returns></returns>
public static bool MapDevice(string strDeviceName, string strTargetPath)
{
return DefineDosDevice(0, strDeviceName, strTargetPath);
}
/// <summary>
/// 卸载虚拟磁盘
/// </summary>
/// <param name="strDeviceName">盘符</param>
/// <returns></returns>
public static bool UnMapDevice(string strDeviceName)
{
return DefineDosDevice(3, strDeviceName, "");
}
private void button1_Click(object sender, EventArgs e)
{
MapDevice("B:",@"C:\Documents and Settings");
}
private void button2_Click(object sender, EventArgs e)
{
UnMapDevice("B:");
}


补上源码:
浙公网安备 33010602011771号