Windows 7在物理驱动器上的WriteFile [英] WriteFile on Physical Drives with Windows 7

查看:142
本文介绍了Windows 7在物理驱动器上的WriteFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码,可以使用WriteFile将扇区写入物理磁盘.在Win XP下可以正常工作,但在Windows 7下(未尝试Vista)不能正常工作.它返回错误代码ERROR_ACCESS_DENIED.阅读 http://msdn.microsoft.com/en-us/library/aa365747%28VS.85%29.aspx [ ^ ]我看到我应该卸下或锁定与物理设备关联的卷.我添加了枚举卷的代码,并使用FSCTL_LOCK_VOLUME调用了DeviceIoControl.现在,当我调用WriteFile时,即使我重复WriteFile调用,也会得到错误代码ERROR_DEVICE_CHANGED.

我该怎么办?

I have a piece of code that writes sectors to a physical disk using WriteFile. This works fine under Win XP, but not under Windows 7 (Not tried Vista). It returns an error code of ERROR_ACCESS_DENIED. Having read http://msdn.microsoft.com/en-us/library/aa365747%28VS.85%29.aspx[^] I can see that I should be dismounting or locking the volumes associated with the physical device. I added code to enumerate the volumes and called DeviceIoControl with FSCTL_LOCK_VOLUME. Now when I call WriteFile I get the error code ERROR_DEVICE_CHANGED, even if I repeat the WriteFile call.

What should I be doing?

推荐答案

Vista和Windows 7不允许您写入物理磁盘或已在其上挂载文件系统的分区,即使以管理员身份也是如此.

锁定驱动器后,您必须卸下驱动器并摆脱DOS设备.要卸下驱动器,请使用带有FSCTL_DISMOUNT_VOLUME的DeviceIoControl.要摆脱DOS设备(即驱动器号),请使用DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE.

希望有帮助,

干杯,

Ash
Vista and Windows 7 don''t let you write to physical disks or partitions that have mounted file systems on, even as an administrator.

After locking the drive you have to dismount it and get rid of the DOS device. To dismount the drive use DeviceIoControl with FSCTL_DISMOUNT_VOLUME. To get rid of the DOS device (i.e. the drive letter) call DefineDosDevice with DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE.

Hope that helps,

Cheers,

Ash


您是否尝试通过右键单击EXE并选择以管理员身份运行"来运行它?
Did you try running it by right clicking on the EXE and select "Run as administrator"?


这篇关于Windows 7在物理驱动器上的WriteFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆