windows NT/2000读写物理,逻辑磁盘扇区
来源:互联网 发布:ev3编程教程 编辑:程序博客网 时间:2024/05/18 02:51
procedure TForm1.Button1Click(Sender: TObject);
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;
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;
- windows NT/2000读写物理,逻辑磁盘扇区
- Windows物理磁盘扇区读写示例总结
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- 使用CreateFile, ReadFile, WriteFile在Windows NT/2000/XP下读写绝对扇区的方法
- 使用CreateFile, ReadFile, WriteFile在Windows NT/2000/XP下读写绝对扇区的方法
- 使用CreateFile, ReadFile, WriteFile在Windows NT/2000/XP下读写绝对扇区的方法
- 使用CreateFile, ReadFile, WriteFile在Windows NT/2000/XP下读写绝对扇区的方法
- 直接读写磁盘扇区
- linux 读写磁盘扇区
- 扇区 物理块 逻辑块
- 物理扇区和逻辑扇区(相对扇区)的关系
- win7的磁盘扇区读写。。。。。。。。。。。。。
- linux 下得到磁盘物理扇区大小
- WinCE下的物理扇区读写
- VC、Linux、vxWorks读写物理扇区小结
- VC、Linux、vxWorks读写物理扇区小结
- 将Asp.Net页面输出到EXCEL里去
- 数据库对象的缓存策略
- 今天看到个aooso.com中国的(alexa)排名网
- 如何提高你的工作效率? 041221
- C# 编码规范和编程好习惯
- windows NT/2000读写物理,逻辑磁盘扇区
- 网络协议X档案全集
- 处理自定义消息
- 民富不等于国强(转与互联网)
- Q1 不同企业的竞争优势(待完成)
- Q2 兰德的竞争优势
- Q3 营销备忘:正规计划也能为小企业所用
- XHTML代码规范
- Q4 社区大学的任务书及目标