DefineDosDevice虚拟的磁盘如何卸载?

fmaliang 2007-01-13 09:07:13
DefineDosDevice(0, "g:", "e:")虚拟了一个G盘,要如何卸载它???
...全文
1802 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
shifagengen 2011-07-26
  • 打赏
  • 举报
回复
试试:DefineDosDevice(DDD_REMOVE_DEFINITION,"G:",NULL);
MORHH 2010-09-06
  • 打赏
  • 举报
回复
不如就用SUBST
swift19221 2010-08-24
  • 打赏
  • 举报
回复
看MSDN,看不懂再问,参数不要用数字,尽量用宏
谁看得懂数字呢,又不是机器。。。
lobtao 2008-06-13
  • 打赏
  • 举报
回复
顶,没有找到满意答案.
UltraBejing 2008-05-01
  • 打赏
  • 举报
回复
这个简单啊,网上搜一下就得到答案了.
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
都是很好的建议! 值得学习
Tiger_Zhao 2007-08-01
  • 打赏
  • 举报
回复
同意 myjian(嗷嗷叫的老马--无业,正在到处游的人.......) ,这与弹出 Usb Disk 一样处理,正在使用就出警告。
嗷嗷叫的老马 2007-07-31
  • 打赏
  • 举报
回复
有文件在使用中,是删除不成功的
zctom23 2007-07-31
  • 打赏
  • 举报
回复
用这个去删删看DefineDosDevice(2, strDisk, vbNullString)

我用这个就可以了
清晨曦月 2007-01-18
  • 打赏
  • 举报
回复
哭ING,,DefineDosDevice是麻,么用过,孤陋寡闻了,

不过一般的东东都支持参数的,例如D-TOOLS,,,就可以用SHELL C:\XXX\D-TOOLS.EXE -XXXX来加载或卸载虚拟盘..
VirtualDesktop 2007-01-16
  • 打赏
  • 举报
回复
DDD_EXACT_MATCH_ON_REMOVE If this value is specified along with DDD_REMOVE_DEFINITION, the function will use an exact match to determine which mapping to remove. Use this value to insure that you do not delete something that you did not define.
VirtualDesktop 2007-01-16
  • 打赏
  • 举报
回复
看msdn:

DefineDosDevice

The DefineDosDevice function defines, redefines, or deletes MS-DOS device names.


BOOL DefineDosDevice(
DWORD dwFlags,
LPCTSTR lpDeviceName,
LPCTSTR lpTargetPath
);

Parameters
dwFlags
[in] Controllable aspects of the DefineDosDevice function. This parameter can be one or more of the following values. Value Meaning
DDD_EXACT_MATCH_ON_REMOVE If this value is specified along with DDD_REMOVE_DEFINITION, the function will use an exact match to determine which mapping to remove. Use this value to insure that you do not delete something that you did not define.
DDD_NO_BROADCAST_SYSTEM Do not broadcast the WM_SETTINGCHANGE message. By default, this message is broadcast to notify the shell and applications of the change.
DDD_RAW_TARGET_PATH Uses the lpTargetPath string as is. Otherwise, it is converted from an MS-DOS path to a path.
DDD_REMOVE_DEFINITION Removes the specified definition for the specified device. To determine which definition to remove, the function walks the list of mappings for the device, looking for a match of lpTargetPath against a prefix of each mapping associated with this device. The first mapping that matches is the one removed, and then the function returns.
If lpTargetPath is NULL or a pointer to a NULL string, the function will remove the first mapping associated with the device and pop the most recent one pushed. If there is nothing left to pop, the device name will be removed.

If this value is not specified, the string pointed to by the lpTargetPath parameter will become the new mapping for this device.


lpDeviceName
[in] Pointer to an MS-DOS device name string specifying the device the function is defining, redefining, or deleting. The device name string must not have a trailing colon, unless a drive letter (C or D, for example) is being defined, redefined, or deleted. In no case is a trailing backslash allowed.
lpTargetPath
[in] Pointer to a path string that will implement this device. The string is an MS-DOS path string unless the DDD_RAW_TARGET_PATH flag is specified, in which case this string is a path string.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
MS-DOS device names are stored as junctions in the object name space. The code that converts an MS-DOS path into a corresponding path uses these junctions to map MS-DOS devices and drive letters. The DefineDosDevice function enables an application to modify the junctions used to implement the MS-DOS device name space.

To retrieve the current mapping for a particular MS-DOS device name or to obtain a list of all MS-DOS devices known to the system, use the QueryDosDevice function.

To define a drive letter assignment that is persistent across boots and not a network share, use the SetVolumeMountPoint function. If the volume to be mounted already has a drive letter assigned to it, use the DeleteVolumeMountPoint function to remove the assignment.

Drive letters and device names defined at system boot time are protected from redefinition and deletion unless the user is an administrator.


Windows Server 2003 and Windows XP: The function creates a device name for a caller that is not running in the LocalSystem context in its own Local MS-DOS device namespace. If the caller is running in the LocalSystem context, the function creates the device name in the Global MS-DOS device namespace. For more information, see Defining an MS DOS Device Name.

Example Code
For an example, see Editing Drive Letter Assignments.

fmaliang 2007-01-14
  • 打赏
  • 举报
回复
ret = DefineDosDevice(0, "F:","\\ml000\game")'建立虚拟盘
ret = DefineDosDevice(2, "F:", vbNull)'删除虚拟盘
用这两条语句有时候能成功,有时候又不行,不知道怎么回事。
dwFlags参数我用过0、1、2、3、4、8,3也可以删除虚拟盘,不知道怎么回事。
gguueesstt 2007-01-13
  • 打赏
  • 举报
回复
API我还未找到,不过你可 使用 SUBST 命令
zsj1101 2007-01-13
  • 打赏
  • 举报
回复
Public Declare Function DefineDosDevice Lib "kernel32" Alias "DefineDosDeviceA" (ByVal dwFlags As Long, ByVal lpDeviceName As String, ByVal lpTargetPath As String) As Long

Sub tt()
Call DefineDosDevice(2, "Z:", "C:\FlashGet")
End Sub


(此资源来自网络,本人不负任何责任) 易 游等等的虚拟还原功能都是用这开发的 一 安装和使用方法: 1 安装:看install.txt文件; 2 挂载:filedisk /mount 0 c:\proj\myfiledisk\a.img e: 3 卸载:filedisk /umount e: 详细看example.txt文件,在本站的下载中心有下载,包括核心层和应用层的源码。 最多可以同时挂4个设备,分别定义4个设备号,如果同一设备号使用2次,会进入OPEN_FILE两次,出现"FileDisk: IOCTL_FILE_DISK_OPEN_FILE: Media already opened\n"的错误提示; 二 基本知识: 1 关于DefineDosDevice函数: 在应用层开发中调用它来创建一个\??目录下的符号链接,如: BOOL okay = DefineDosDevice(DDD_RAW_TARGET_PATH, "test", "\\Device\\FileDisk0"); 调用成功后,将会在设备命名空间的\??目录下生成一个名为”test“的符号链接,该链接指向”“\\Device\\FileDisk0“这个对象。 而在核心态的驱动程序中,需要调用以下的函数来创建相应的符号链接: IoCreateSymbolicLink(linkname, targname); Linkname是要创建的符号链接名,相当于上面函数中的”test”,targname是该链接指向的设备对象。 2 filedisk的源映像可以是img,iso,flp等,这些都是磁盘上一个分区的平面映像,所以挂上后可以直接访问,但不能是整个硬盘的img映像或其它格式如rar等; 3 filedisk的源映像文件名称必须是全路径,即使是在当前目录下也必须是全路径; 4 源映像文件如果不存在且参数中没有指定只读,那么只要在参数中指定了大小则会主动创建它,使用前会提示先“格式化”,之后就可正常使用了; 三 核心层源码分析: 1 DriverEntry: 主函数入口;备份传入路径,查询注册表值,调用ZwCreateDirectoryObject创建设备目录,重复4次调用 FileDiskCreateDevice创建设备,初始化操作函数指针。 2 FileDiskCreateDevice:调用IoCreateDevice创建设备,KeInitializeEvent初始化事件对象,PsCreateSystemThread创建内核线程,入口函数是FileDiskThread,传入的函数参数为IoCreateDevice返回的设备对象。 3 FileDiskThread:首先调用KeSetPriorityThread更改自身线程的优先级为LOW_REALTIME_PRIORITY,然后开始for(;;),调用KeWaitForSingleObject函数等待事件对象有信号,如果等到,判断事件类型,有如下几种: IRP_MJ_READ:调用ZwReadFile读取文件,从内核到用户缓冲区; IRP_MJ_WRITE:调用ZwWriteFile写入文件,从用户到内核缓冲区; IRP_MJ_DEVICE_CONTROL:在FileDiskDeviceControl设置事件才会触发,主要有如下两种操作码: IOCTL_FILE_DISK_OPEN_FILE:调用FileDiskOpenFile。 IOCTL_FILE_DISK_CLOSE_FILE:调用FileDiskCloseFile。 FileDiskOpenFile:根据用户程序传入的映像文件全路径,调用ZwCreateFile在内核中打开它,如果文件不存在则再创建它,返回文件句柄。 FileDiskCloseFile:调用ZwClose关闭文件。 4 FileDiskCreateClose: 仅返回成功;对应Create,Close操作。 5 FileDiskReadWrite:将IO包插入队列,然后调用KeSetEvent函数,激活事件对象;对应Read,Write操作。 6 FileDiskDeviceControl:用户程序调用DeviceIoControl的响应函数,主要有如下两种操作: IOCTL_FILE_DISK_OPEN_FILE:设置好参数,将IO包插入队列,设置对象为有信号。 IOCTL_FILE_DISK_CLOSE_FILE:将IO包插入队列,设置对象为有信号。 其它的操作类型因为输入输出共用一个缓冲区,所以都采用系统默认处理,设置好需要输出的参数后,就直接从这个函数返回了。如: IOCTL_DISK_GET_DRIVE_GEOMETRY,IOCTL_CDROM_GET_DRIVE_GEOMETRY等; 7 有4种操作是自定义的:FileDiskReadWrite函数两种,FileDiskDeviceControl函数两种,对应的操作码分别是: IRP_MJ_READ,IRP_MJ_WRITE,IOCTL_FILE_DISK_OPEN_FILE,IOCTL_FILE_DISK_CLOSE_FILE这4种,在FileDiskThread中等待这4种事件发生,如果等到,就调用相应的函数处理。 四 应用层源码分析: 1 mount:调用DefineDosDevice在应用层创建一个指向设备命名空间的符号链接,用CreateFile打开此链接,然后调用DeviceIoControl,控制码是IOCTL_FILE_DISK_OPEN_FILE,内核程序响应后,执行真正打开源映像文件的操作。 2 umount: 上面大致一样,只是多一些步骤,不同的是控制码改为IOCTL_FILE_DISK_CLOSE_FILE,之后必须发送FSCTL_DISMOUNT_VOLUME
转自看雪的CCDeath 【文章标题】: WinMount虚拟磁盘深入研究(-)之filedisk源代码详细分析 【下载地址】: 自己搜索下载 【作者声明】: 只是感兴趣,没有其他目的。失误之处敬请诸位大侠赐教! -------------------------------------------------------------------------------- 【详细过程】 我的驱动入门三终结版,还再学习中。由于个人也有些事情要处理,研究起刘涛涛WinMount的虚拟 磁盘,而且这方面的书籍,貌似乎没见过,只有傻傻的几K代码存在,没注释什么的,整体框架也没说。 虚拟光驱用实现文件来模拟磁盘的原理,是文件系统驱动程序。 把filedisk驱动安装,查看install.txt文件。 1.Copy the driver (filedisk.sys) to %systemroot%\system32\drivers\. 2.Import filedisk.reg to the Registry. 3.Reboot. 4.Use the program filedisk.exe to mount/umount files, for an example of use see the file example.txt. 可以不用重起机子的方法,找一个动载加载驱动工具:DriverMonitor不错了。然后在“开始菜单”-> "运行"输入 "net start filedisk" 出现:“ 请求的服务已经启动”。这个必须得成功才行哦。 接下来注意点。cmd后 出现这个目录 C:\Documents and Settings \Administrator>,在接下来敲入 filedisk /mount 0 c:\temp\filedisk.img 8M f: C:\Documents and Settings \Administrator>filedisk /mount 0 c:\temp\filedisk.img 8M r: 回车一下。 出现"FileDisk:系统找不到指定路径" 。原因就出在这 "c:\temp\filedisk.img" 中的C:\temp要这个目录才行。至于 filedisk.img不是必须,会自动创建。 如果有出现"FileDisk:函数不正确" 中的“filedisk /mount 0 ”中"0"代号已经被使用。可以改为"1". 查看一下,结果就出现一个还未格式化 8M R磁盘,查看C:\temp下生成一个filedisk.img也8M。想卸载 掉"filedisk /umount r:". 还可以创建很大的虚拟磁盘,你把"8M"改换其他的就是了。 以上如果都没出现结果,基本上就没兴趣继续研究下去了,我看到了很多人初学filedisk都遇到以上这 些问题(包括我在内) ,把我折腾了半天。 先来分析驱动层代码,后来分析应用层代码。更详细的请看附件里的源代码。我对代码工程方式重新布 局,用起来更方便。 ===================================//先来分析驱动层代码 1.对filedisk.h进行分析 #define FILE_DEVICE_FILE_DISK 0x8000//用户定义范围0x8000~ #define IOCTL_FILE_DISK_OPEN_FILE CTL_CODE(FILE_DEVICE_FILE_DISK, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_FILE_DISK_CLOSE_FILE CTL_CODE(FILE_DEVICE_FILE_DISK, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_FILE_DISK_QUERY_FILE CTL_CODE(FILE_DEVICE_FILE_DISK, 0x802, METHOD_BUFFERED, FILE_READ_ACCESS) typedef struct _OPEN_FILE_INFORMATION { LARGE_INTEGER FileSize;//文件大小 BOOLEAN ReadOnly;//只读属性 USHORT Fil

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧