H
happytimes_dsq
Unregistered / Unconfirmed
GUEST, unregistred user!
之前做的清楚程序,清除的是后面的逻辑分区的数据,并没有把U盘最前面的物理磁盘引导区清除(我用WINHEX对比得到的,别的工具好象看不出).有位大侠说我应该先找到对应物理磁盘在系统下的编号,然后format('//./PHYSICALDRIVE%d', [0]);找了些资料代码.原来有些兄弟也问过,不过都没有完整的答案.比较多的是这段代码,但是它怎么返回都是0,没有正确的编号! 请教大家了! 这段代码哪里不对或者 有什么更好的方法.
const
FILE_ANY_ACCESS = 0;
METHOD_BUFFERED = 0;
IOCTL_VOLUME_BASE = DWORD('V');
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = (
(IOCTL_VOLUME_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or
(0 shl 2) or METHOD_BUFFERED);
type
TDiskExtent = record
DiskNumber: DWORD;
StartingOffset: LARGE_INTEGER;
ExtentLength: LARGE_INTEGER;
end;
TVolumeDiskExtents = record
NumberOfDiskExtents: DWORD;
Extents: array [0..0] of TDiskExtent;
end;
PVolumeDiskExtents = ^TVolumeDiskExtents;
function TForm1.GetVolumeInfo(DriverLetter: Char): TDiskExtent;
var
hVolume: THandle;
DiskExtents: PVolumeDiskExtents;
dwOutBytes: Cardinal;
begin
with Result do
begin
DiskNumber := 0;
StartingOffset.QuadPart := 0;
ExtentLength.QuadPart := 0;
end;
hVolume := CreateFile(PChar('//./'+DriverLetter+':'), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hVolume < 1 then Exit;
DiskExtents := AllocMem(Max_Path);
if DeviceIoControl(hVolume,
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
nil, 0,
DiskExtents, Max_Path,
dwOutBytes, nil) then
begin
if DiskExtents^.NumberOfDiskExtents > 0 then
Result := DiskExtents^.Extents[0];
end;
FreeMem(DiskExtents);
CloseHandle(hVolume);
end;
const
FILE_ANY_ACCESS = 0;
METHOD_BUFFERED = 0;
IOCTL_VOLUME_BASE = DWORD('V');
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = (
(IOCTL_VOLUME_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or
(0 shl 2) or METHOD_BUFFERED);
type
TDiskExtent = record
DiskNumber: DWORD;
StartingOffset: LARGE_INTEGER;
ExtentLength: LARGE_INTEGER;
end;
TVolumeDiskExtents = record
NumberOfDiskExtents: DWORD;
Extents: array [0..0] of TDiskExtent;
end;
PVolumeDiskExtents = ^TVolumeDiskExtents;
function TForm1.GetVolumeInfo(DriverLetter: Char): TDiskExtent;
var
hVolume: THandle;
DiskExtents: PVolumeDiskExtents;
dwOutBytes: Cardinal;
begin
with Result do
begin
DiskNumber := 0;
StartingOffset.QuadPart := 0;
ExtentLength.QuadPart := 0;
end;
hVolume := CreateFile(PChar('//./'+DriverLetter+':'), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hVolume < 1 then Exit;
DiskExtents := AllocMem(Max_Path);
if DeviceIoControl(hVolume,
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
nil, 0,
DiskExtents, Max_Path,
dwOutBytes, nil) then
begin
if DiskExtents^.NumberOfDiskExtents > 0 then
Result := DiskExtents^.Extents[0];
end;
FreeMem(DiskExtents);
CloseHandle(hVolume);
end;