现在的位置: 首页 > 综合 > 正文

【探索发现】.NET 创建虚拟磁盘

2013年07月11日 ⁄ 综合 ⁄ 共 806字 ⁄ 字号 评论关闭

呵呵 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:");
        }

补上源码:

http://files.cnblogs.com/--Sam--/VirtualDevice.rar

抱歉!评论已关闭.