WriteFile错误#5“拒绝访问”下win Vista / 7 [英] WriteFile error #5 "denied access" under win Vista/seven

查看:976
本文介绍了WriteFile错误#5“拒绝访问”下win Vista / 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我googled了很多,我找不到任何答案这个问题...

I googled a lot and I couldn't find any answer to this problem...

我有一个C ++控制台应用程序读取1GB的SD卡,修复不正确地关闭文件并相应地写入FAT表。 SD卡最初由定制设备中的固件编写。
它工作正常到Xp和停止工作在Win Vista /七。
我尝试提升权限:在管理员帐户类型中,我使用以管理员身份运行方法启动了cmd窗口,但没有运气。
我也尝试过一个清单,要求highestAvailable特权,但没有运气。

I have a C++ console application that reads a 1GB SD card that fixes improperly closed files and writes the FAT table accordingly. The SD card is written at the beginning by a firmware in a custom made device. It worked OK up to Xp and stopped working in Win Vista/seven. I tried elevating privileges: within an administrator account type, I launched a cmd window using the "run as administrator" method but no luck. I also tried with a manifest asking for highestAvailable privileges but no luck.

我读了一些帖子,Windows Vista不允许您访问磁盘从用户模式进程。是否有人知道绕过这种行为的任何方式?

I read in some post that "Windows Vista doesn't allow you to access the disks from user-mode processes at all. Does anybody know about any way of bypassing this behavior?

我在解决方法中工作,但我想知道这是不可能的

I’m working in a workaround however I would like to know if this is impossible or not

编辑

这是我在这里的第一篇文章,问题...但我根本没有任何垃圾邮件...只是在一个社区驱动的网站:)

This is my first post here so I don't quite understand about the linking issue... But I'm not reated to any spam at all... just asking in a comunity driven site :)

代码看起来像

hDevice = CreateFile(buffer,GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING,0,NULL); 

然后我从SD读取BTB信息,查找并关闭不正确的文件。

I then read the BTB information from the SD and look for and improperly closed file.

最后尝试写入SD

WriteFile(hDevice,buffer,SD_SECTOR_SIZE, &temp, 0)

我得到访问被拒绝(错误#5)

I get an Access denied (error #5)

CreateFile()上的字符串是\.\g:因为g字母对应于我的机器上的SD卡。所有的工作确定,正如我之前说过的XP在XP。我也尝试使用:DeviceIoControl with FSCTL_LOCK_VOLUME但是给出一个mem错误错误。

The string on CreateFile() is \.\g: as the g letter correspond to the SD card on my machine. All that works ok and as I said before it woks on XP. I also tried using: DeviceIoControl with FSCTL_LOCK_VOLUME but that gives a mem fault error.

希望这有助于理解和感谢任何帮助

Hope this helps to understand and thanks for any help

推荐答案

我认为这是由于路径字符串buffer;我碰到了同样的问题。
您用于获取设备访问的路径需要看起来像这个\\.\PhysicalDrive%d
%d是驱动器的十进制数。

I think this is due to the path string "buffer"; I ran into the same issue. The path you are using to get device access needs to look lik this "\\.\PhysicalDrive%d" %d is the decimal number of the drive.

从Vista这个字符串是CASE SENSITIVE。
检查拼写。您还需要管理员权限,与以前在XP中一样。

From Vista on this string is CASE SENSITIVE. Check the spelling. You also need admin rights, just as before in XP.

对于卷。该信件需要CAPITALIZED
例如\\.\G:

For Volumes,. the letter needs to CAPITALIZED e.g. "\\.\G:"

另请注意,将SD卡作为设备而不是卷访问更好,因为如果Windows安装

Also note that it is much better to access the SD card as a device rathern than the volume, since if Windows mounts it, there might be a file system mounted with a write cache.

此外:我忘了提到你的读/写数据的缓冲区应该是页面并且读取扇区大小的倍数。
VirtualAlloc()执行此

Furthermore: I forgot to mention that the buffer your read/write the data to/from should be page aligned and the read a multiple of the sector size. VirtualAlloc() does this

这篇关于WriteFile错误#5“拒绝访问”下win Vista / 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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