---------------也许不该放到这里,但我真的需要直接读取硬盘上的数据块-------- 1,要读取mbr数据,不能直接通过read之类的函数,不知道delphi可不可以直接读硬盘,如何读?2,能不能随意指定要读取的硬盘扇区,怎么指定?唉,这问题有点变态,实在解决不了,只有在这里问高手了。分不够再加!~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以读,但应该不是用READ之类的函数可以写一段汇编程序来读。 我在debug里用int13读出来了,但在delphi里怎么调用int13呢? windows NT/2000读写物理,逻辑磁盘扇区var hDriveHandle: THandle;procedure TForm1.Button1Click(Sender: TObject);const BytesPerSector = 512; SectorCount = 1; //读写扇区数 SectorStart = 0; //起始扇区数 drive = '\\.\C:'; //驱动盘var str: String; p: PChar; i: Cardinal;begin hDriveHandle := CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if (hDriveHandle <> INVALID_HANDLE_VALUE) then begin p := allocmem(SectorCount * ByteSPerSector);//p 必须是新申请的内存或全局变量,不能是局部变量 //定义为局部变量是不能读写磁盘的 FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区 if FileRead(hDriveHandle, p[0], SectorCount * BytesperSector)<> //读扇区 SectorCount * BytesperSector then raise Exception.Create('Read Error!'); str :=''; for i := 0 to 512 - 1 do begin str := str + Format('%.2x', [integer(p[i])]); if i mod 16 = 15 then str := str + #13; end; ShowMessage(str); FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区 if FileWrite(hDriveHandle, p[0], SectorCount * BytesperSector)<> //写扇区 SectorCount * BytesperSector then raise Exception.Create('Write Error!'); FreeMem(p, SectorCount * BytesperSector); Closehandle(hDriveHandle); end;end;procedure TForm1.Button2Click(Sender: TObject);const BytesPerSector = 512; SectorCount = 1; //读写扇区数 SectorStart = 0; //起始扇区数 drive = '\\.\PHYSICALDRIVE0'; //物理磁盘var str: String; p: PChar; i: Cardinal;begin hDriveHandle := CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if (hDriveHandle <> INVALID_HANDLE_VALUE) then begin p := allocmem(SectorCount * ByteSPerSector);//p 必须是新申请的内存或全局变量,不能是局部变量 //定义为局部变量是不能读写磁盘的 FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区 if FileRead(hDriveHandle, p[0], SectorCount * BytesperSector)<> //读扇区 SectorCount * BytesperSector then raise Exception.Create('Read Error!'); str :=''; for i := 0 to 512 - 1 do begin str := str + Format('%.2x', [integer(p[i])]); if i mod 16 = 15 then str := str + #13; end; ShowMessage(str); FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区 if FileWrite(hDriveHandle, p[0], SectorCount * BytesperSector)<> //写扇区 SectorCount * BytesperSector then raise Exception.Create('Write Error!'); FreeMem(p, SectorCount * BytesperSector); Closehandle(hDriveHandle); end;end; 函数确实一样但是CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);的参数drive不同drive = '\\.\C:'; //驱动盘drive = '\\.\PHYSICALDRIVE0'; //物理磁盘 http://vip.6to23.com/wenjinshan/ 8. Windows直接读写磁盘扇区的源代码,高技术含量!成功解决Windows下读写磁盘的问题,支持9x/NT/2000/XP,分逻辑磁盘扇区、物理磁盘扇区两种方式(见出版书籍的《Windows核心编程》一书) TO:meiqingsong(阿飛) CreateFile()函数的参数是怎么设定的?我没有在delphi帮助上找到合适的说明啊。 FileRead()读扇区的原理是什么?谢谢了~~ 1.CreateFile()函数的参数是怎么设定的?--在delphi帮助上有, 帮助 -〉windows sdk 中,查CreateFile, 在 “找到主题“ 的对话框中选择 CreateFile(win32 programmer's reference)2.windows NT/2000读写物理,逻辑磁盘扇区的关键不在于FileRead(),而在于用 CreateFile()获得物理,逻辑磁盘扇区的句柄 delphi线程中如何读取webservice返回的数据集 delphi7 怎样获得查询时间 怎么取月初和月末的日期,并且让它在每个月的月初提示 关于DBGridDrawColumnCell的一个奇怪问题 关于spcomm 在线等答案,急 delphi+access关于日期时间字段的查询问题! 可以告诉我哪儿错了吗? 请教问题: 如何在DBGrid中嵌入其他控件..?求各位大侠帮帮忙.... 怎么知道显示在dbedit中的记录被修改?(记录未移动之前) delphi精彩讨论100篇 Delphi 插入记录异常时,怎么判断是不是因为唯一性的原因?
可以写一段汇编程序来读。
hDriveHandle: THandle;
procedure TForm1.Button1Click(Sender: TObject);
const
BytesPerSector = 512;
SectorCount = 1; //读写扇区数
SectorStart = 0; //起始扇区数
drive = '\\.\C:'; //驱动盘
var
str: String;
p: PChar;
i: Cardinal;
begin
hDriveHandle := CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0);
if (hDriveHandle <> INVALID_HANDLE_VALUE) then
begin
p := allocmem(SectorCount * ByteSPerSector);//p 必须是新申请的内存或全局变量,不能是局部变量
//定义为局部变量是不能读写磁盘的
FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区
if FileRead(hDriveHandle, p[0], SectorCount * BytesperSector)<> //读扇区
SectorCount * BytesperSector then
raise Exception.Create('Read Error!');
str :='';
for i := 0 to 512 - 1 do
begin
str := str + Format('%.2x', [integer(p[i])]);
if i mod 16 = 15 then
str := str + #13;
end;
ShowMessage(str); FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区
if FileWrite(hDriveHandle, p[0], SectorCount * BytesperSector)<> //写扇区
SectorCount * BytesperSector then
raise Exception.Create('Write Error!'); FreeMem(p, SectorCount * BytesperSector);
Closehandle(hDriveHandle);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
const
BytesPerSector = 512;
SectorCount = 1; //读写扇区数
SectorStart = 0; //起始扇区数
drive = '\\.\PHYSICALDRIVE0'; //物理磁盘
var
str: String;
p: PChar;
i: Cardinal;
begin
hDriveHandle := CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0);
if (hDriveHandle <> INVALID_HANDLE_VALUE) then
begin
p := allocmem(SectorCount * ByteSPerSector);//p 必须是新申请的内存或全局变量,不能是局部变量
//定义为局部变量是不能读写磁盘的
FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区
if FileRead(hDriveHandle, p[0], SectorCount * BytesperSector)<> //读扇区
SectorCount * BytesperSector then
raise Exception.Create('Read Error!');
str :='';
for i := 0 to 512 - 1 do
begin
str := str + Format('%.2x', [integer(p[i])]);
if i mod 16 = 15 then
str := str + #13;
end;
ShowMessage(str); FileSeek(hDriveHandle, SectorStart * BytesPerSector, 0); //起始扇区
if FileWrite(hDriveHandle, p[0], SectorCount * BytesperSector)<> //写扇区
SectorCount * BytesperSector then
raise Exception.Create('Write Error!'); FreeMem(p, SectorCount * BytesperSector);
Closehandle(hDriveHandle);
end;
end;
CreateFile(drive, GENERIC_ALL, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0);
的参数drive不同
drive = '\\.\C:'; //驱动盘
drive = '\\.\PHYSICALDRIVE0'; //物理磁盘
CreateFile()函数的参数是怎么设定的?我没有在delphi帮助上找到合适的说明啊。
FileRead()读扇区的原理是什么?谢谢了~~
--在delphi帮助上有,
帮助 -〉windows sdk 中,查CreateFile,
在 “找到主题“ 的对话框中选择 CreateFile(win32 programmer's reference)
2.windows NT/2000读写物理,逻辑磁盘扇区的关键不在于FileRead(),
而在于用 CreateFile()获得物理,逻辑磁盘扇区的句柄