DeviceIoControl()
-
Hallo,
der folgende Aufruf der Funktion DeviceIoControl() schlägt fehl, GetLastError() --> 5
bool GetDriveLayOut(DRIVE_LAYOUT_INFORMATION *layout, AnsiString PhysDrive) { HANDLE hDevice; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results hDevice = CreateFile(PhysDrive.c_str(), // drive to open 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { return (FALSE); } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_LAYOUT, // operation to perform NULL, 0, // no input buffer layout, sizeof(*layout), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O CloseHandle(hDevice); return (bResult); }
der selbe Funktionsaufruf mit der Operation:
IOCTL_DISK_GET_DRIVE_GEOMETRY
an Stelle von:
IOCTL_DISK_GET_DRIVE_LAYOUTfunktioniert.
Hat jemand eine Idee ??
Danke Torsten
-
Error code 5 -> Zugriff verweigert
dürfte klar sein wenn du dir den Code nochmal ansiehst ("// no access to the drive" hmmm??)
-
hmm hilf mir mal auf die Sprünge..
Ich rufe die Funktion so auf:GetDriveLayOut(DLI,"\\\.\\PhysicalDrive0")..
Wieso erhalte ich als Fehlermeldung "Zugriff verweigert" ??
Danke für Eure Geduld
Torsten
-
also dann gibt noch mal nen kleinen schubs in die richtung:
bool GetDriveLayOut(DRIVE_LAYOUT_INFORMATION *layout, AnsiString PhysDrive) { HANDLE hDevice; // handle to the drive to be examined BOOL bResult; // results flag DWORD junk; // discard results hDevice = CreateFile(PhysDrive.c_str(), // drive to open //|||||||||||||||||||||||||||||||||||||||||||||||||||| // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0, // no access to the drive <-- ?????? //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //|||||||||||||||||||||||||||||||||||||||||||||||||||| FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive { return (FALSE); } bResult = DeviceIoControl(hDevice, // device to be queried IOCTL_DISK_GET_DRIVE_LAYOUT, // operation to perform NULL, 0, // no input buffer layout, sizeof(*layout), // output buffer &junk, // # bytes returned (LPOVERLAPPED) NULL); // synchronous I/O CloseHandle(hDevice); return (bResult); }
"no access to the drive" würde ich mal so frei als "kein zugrif.." übersetzten.
Und NEIN ich post jetzt nicht den richtigen code, in der MSDN steht ganz dick und fett was da hin gehört.[ Dieser Beitrag wurde am 10.12.2002 um 00:08 Uhr von CMatt editiert. ]
-
Vielen Dank an den genialen CMatt.
Hast mir sehr geholfen.