Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Partitionstabelle ändern (https://www.delphipraxis.net/136886-partitionstabelle-aendern.html)

WorstNightmare 11. Jul 2009 10:42

Re: Partitionstabelle ändern
 
Delphi-Quellcode:
  hDisk := CreateFile('\\.\N:', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);

  if hDisk = INVALID_HANDLE_VALUE then
    raise Exception.Create('fail');

  if not DeviceIOControl(hDisk, IOCTL_STORAGE_EJECT_MEDIA, nil, 0, nil, 0, written, nil) then
    SHowmessage('fail2');

  CloseHandle(hDisk);
Es kommt immer fail2, auch wenn ich es mit der gesamten Festplatte versuche... :(

Zu deinem anderen Link:
VolumeInfo.Refresh Method
Checks the hardware to refresh information about volumes.
Namespace: Microsoft.SPOT.IO

Das klingt ja wunderbar, aber ich denke von Delphi aus kann ich nicht auf diesen Namespace zugreifen, oder? :wink:

hathor 11. Jul 2009 13:16

Re: Partitionstabelle ändern
 
Versuche es mit IOCTL_VOLUME_OFFLINE:

Delphi-Quellcode:
(*BOOL DeviceIoControl(
  (HANDLE) hDevice,            // handle to device
  IOCTL_VOLUME_OFFLINE,        // dwIoControlCode
  NULL,                        // lpInBuffer
  0,                           // nInBufferSize
  NULL,                        // lpOutBuffer
  0,                           // nOutBufferSize
  (LPDWORD) lpBytesReturned,   // number of bytes returned
  (LPOVERLAPPED) lpOverlapped); // OVERLAPPED structure
---- *)
if DeviceIOControl(hDevice, IOCTL_VOLUME_OFFLINE, nil, 0, @dg,
        sizeof(dg), dummy, nil) = true then
      begin...

WorstNightmare 11. Jul 2009 15:53

Re: Partitionstabelle ändern
 
So, auf MSDN stand bei IOCTL_VOLUME_OFFLINE, dass man ruhig alles hintereinander ausführen soll:

Delphi-Quellcode:
  hDisk := CreateFile('\\.\N:', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);

  if hDisk = INVALID_HANDLE_VALUE then
    raise Exception.Create('opening failed');

  if not LockVolume(hDisk) then
    Showmessage('not locked!!');

  if not DeviceIOControl(hDisk, FSCTL_DISMOUNT_VOLUME, nil, 0, nil, 0, written, nil) then
    Showmessage('dismounting failed');

  if not DeviceIOControl(hDisk, IOCTL_VOLUME_OFFLINE, nil, 0, nil, 0, written, nil) then
    Showmessage('still online!!!');

  CloseHandle(hDisk);
Der Code ansich funktioniert, es kommt keine Meldung.
In Windows wird das Laufwerk als "Lokaler Datenträger" angezeigt, hat keine Größe und ich habe auch keinen Zugriff mehr darauf. Kann ich jetzt noch irgendwas danach ausführen, dass Windows ihn endgültig rauswirft?

Aber dass er jetzt schonmal unbenutzbar ist finde ich gut, danke für die bisherige Hilfe.

Auf MSDN steht auch noch, dass man danach das Gerät "Deinstallieren" kann, ich konnte aber nicht herausfinden wie das geht.

Ich habe auch folgende Codes ausprobiert, alle schlugen mit False als Ergebnis fehl (Funktion/Anforderung wird nicht unterstützt)

IOCTL_STORAGE_RESET_DEVICE
IOCTL_DISK_EJECT_MEDIA
IOCTL_DISK_REMOVE_DEVICE
IOCTL_STORAGE_EJECT_MEDIA

Edit: Ich mach mal einen neuen Thread auf, das hat ja nicht mehr 100%ig was mit der eigentlich Frage zu tun.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:01 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz