Getting all partitions on a Drive using DeviceIoControl

I am trying to get details on all the partitions on a physical drive, but I
am getting an access denied message with the call to DeviceIOControl.

This is my code, the account I am using while testing has local admin rights
on the computer, and I am writing it using Delphi… on a Windows 2000
Server machine

The value of IOCTL_DISK_GET_DRIVE_LAYOUT is 475148 decimal or 7400c hex.

PARTITION_INFORMATION = RECORD
StartingOffset: TLargeInteger;
PartitionLength: TLargeInteger;
HiddenSectors: DWORD;
PartitionNumber: DWORD;
PartitionType: BYTE;
BootIndicator: WordBool;
RecognizedPartition: WordBool;
RewritePartition: WordBool;
end;

DRIVE_LAYOUT_INFORMATION = Record
PartitionCount : DWORD;
Signature : DWORD;
Partitioninfo: array[0…1] of PARTITION_INFORMATION;
end;

Function GetDiskGeometry(DriveNum : Longint) : PARTITION_INFORMATION;
Var
RetBytes : DWORD;
hDevice : Longint;
Status : Longbool;
Drive : String;
Layout : DRIVE_LAYOUT_INFORMATION;
begin
Drive := ‘\.\PHYSICALDRIVE’ + inttostr(DriveNum);
hDevice := CreateFile(PChar(Drive),0, FILE_SHARE_READ Or
FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
If hDevice <> INVALID_HANDLE_VALUE Then
begin
Status := DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT,
nil, 0, @Layout, Sizeof(DRIVE_LAYOUT_INFORMATION), RetBytes, nil);
if (status = false) then
showmessage('Failed : '+inttostr(getLastError()));
showmessage(inttostr(Layout.PartitionCount));
CloseHandle(hDevice);
end;
End;

Can anyone spot anything with my code that is bad? or know why I could be
getting the access denied message?

If anyone has any C++ or VB or Delphi sample code please forward it to me as
I am stumped!

Chris


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com