用CreateFile打开物理磁盘,\\\\.\\PhysicalDrive0不行啊解决方法
用CreateFile打开物理磁盘,\\\\.\\PhysicalDrive0不行啊
下面的代码CreateFile返回错误值87,参数错误。
如果我把PhysicalDrive0改成PhysicalDriver0,返回错误2,找不到设备。
应该怎么改呢?
------解决方案--------------------
CREATE_ALWAYS改为OPEN_ALWAYS。
CREATE_ALWAYS:Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes;
OPEN_ALWAYS:Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW
------解决方案--------------------
同楼上, 那个文件是不是,已经存在了。或者该路径不支持创建文件。
------解决方案--------------------
------解决方案--------------------
应该是创建成功了的啊,不晓得其他情况了
------解决方案--------------------
要不把“FILE_SHARE_READ”设置为0看看?
------解决方案--------------------
我试了一下像下面这样,也是不成功哦:
下面的代码CreateFile返回错误值87,参数错误。
如果我把PhysicalDrive0改成PhysicalDriver0,返回错误2,找不到设备。
应该怎么改呢?
- C/C++ code
#include "stdafx.h" #include <windows.h> #include <stdio.h> #include <stdlib.h> int main() { HANDLE hFile=CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(INVALID_HANDLE_VALUE==hFile){ printf("open error %d\n",GetLastError()); } return 0; }
------解决方案--------------------
CREATE_ALWAYS改为OPEN_ALWAYS。
CREATE_ALWAYS:Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes;
OPEN_ALWAYS:Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW
------解决方案--------------------
同楼上, 那个文件是不是,已经存在了。或者该路径不支持创建文件。
------解决方案--------------------
------解决方案--------------------
应该是创建成功了的啊,不晓得其他情况了
------解决方案--------------------
要不把“FILE_SHARE_READ”设置为0看看?
------解决方案--------------------
我试了一下像下面这样,也是不成功哦:
- C/C++ code
#include "stdafx.h" #include <windows.h> #include <stdio.h> int main() { HANDLE hFile=CreateFile(_TEXT("\\\\.\\PhysicalDriver1"),GENERIC_READ, 0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(INVALID_HANDLE_VALUE==hFile){ printf("open error %d\n",GetLastError()); } return 0; }
------解决方案--------------------
物理磁盘真还没用到过,不知什么地方会用到。
------解决方案--------------------
应该是这个吧~~~~HarddiskVolume0
貌似我在驱动下接收到得路径就是Deivce\HarddiskVolume0这样的形式的
------解决方案--------------------
找开物理磁盘,好鸡巴凶险! 给你上个瞧瞧
// char cFilePath[] = "\\\\.\\E:\\TTTT.txt" ; //文件路径(一定要正确!)
//char cPhisycalDiskPath[] = "\\\\.\\PhysicalDrive0";
HANDLE hFile = CreateFile(cPhisycalDiskPath, GENERIC_READ, FILE_SHARE_READ , NULL, OPEN_EXISTING, 0, NULL );
if(hFile == INVALID_HANDLE_VALUE){
MessageBox(0, "can't open the disk!", 0, 0);
return 0;
}//end of if
------解决方案--------------------
- C/C++ code
hDrive = CreateFile( "\\\\.\\PHYSICALDRIVE0", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);