vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: CD-Nr und Disk-Image 
Autor: Radeonmaster
Datum: 16.12.04 07:58

Zu 2.:
Ich hab's noch nie mit Disketten probiert, muss aber ansich funktionieren.
Leider nur für NT und aufwärts.
In ein Modul:
Option Explicit
 
'*****************************************************************
' Module for performing Direct Read/Write access to disk sectors
'
' Written by Arkadiy Olovyannikov (ark@fesma.ru)
'
' formated, cutted, fixed and commented by rm_code
'*****************************************************************
 
Private Const FILE_BEGIN = 0                ' file begin at byte 0
 
'function for reading from a drive (only NT)
Public Function DirectReadDriveNT(ByVal sDrive As String, ByVal iStartSec As _
  Long, ByVal iOffset As Long, ByRef ret() As Byte, Optional ByVal cBytes As _
  Long = -1) As Boolean
    Dim hDevice As Long, nSectors As Long, nRead As Long, BytesPerSector As Long
    Dim abBuff() As Byte, abResult() As Byte
    Dim sd As SECURITY_ATTRIBUTES
 
    'get the size of a disk sector in bytes
    If Not GetSectorSize(sDrive, BytesPerSector) Then Exit Function
 
    If cBytes = -1 Or cBytes < 1 Then cBytes = BytesPerSector
 
    'get the number of sectors to read
    nSectors = Int((iOffset + cBytes - 1) / BytesPerSector) + 1
 
    'open the drive
    hDevice = CreateFile("\\.\" & UCase(Left(sDrive, 1)) & ":", _
                         GENERIC_READ Or GENERIC_WRITE, _
                         FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                         sd, OPEN_EXISTING, 0&, 0&)
 
    'check for a valid drive handle
    If hDevice = INVALID_HANDLE_VALUE Then Exit Function
 
    'set the filepointer to the first sector we want to read
    SetFilePointer hDevice, iStartSec * BytesPerSector, 0, FILE_BEGIN
 
    'prepare the buffers
    ReDim abResult(cBytes - 1)
    ReDim abBuff(nSectors * BytesPerSector - 1)
 
    'read the sectors and close the handle to the drive
    ReadFile hDevice, abBuff(0), UBound(abBuff) + 1, nRead, 0&
    CloseHandle hDevice
 
    'copy the bytes from the read buffer to the result buffer...
    CopyMemory abResult(0), abBuff(iOffset), cBytes
 
    '... and return it
    ret = abResult
    DirectReadDriveNT = True
End Function
 
'function for writing to a drive (only NT)
Public Function DirectWriteDriveNT(ByVal sDrive As String, ByVal iStartSec As _
  Long, ByVal iOffset As Long, ByVal sWrite As String) As Boolean
    Dim hDevice As Long, nRead As Long, nSectors As Long, BytesPerSector As Long
    Dim sd As SECURITY_ATTRIBUTES
    Dim abBuff() As Byte, ab() As Byte
 
    'get the size of a disk sector in bytes
    If Not GetSectorSize(sDrive, BytesPerSector) Then Exit Function
 
    'get the number of sectors to read
    nSectors = Int((iOffset + Len(sWrite) - 1) / BytesPerSector) + 1
 
    'open the drive
    hDevice = CreateFile("\\.\" & UCase(Left(sDrive, 1)) & ":", _
                         GENERIC_READ Or GENERIC_WRITE, _
                         FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                         sd, OPEN_EXISTING, 0&, 0&)
 
    'check for a valid drive handle
    If hDevice = INVALID_HANDLE_VALUE Then Exit Function
 
    'fill the write buffer with the data from the sectors we want to overwrite,
    'because we have the option to start writing from an offset
    DirectReadDriveNT sDrive, iStartSec, 0, abBuff, nSectors * BytesPerSector
    ab = StrConv(sWrite, vbFromUnicode)
 
    'add the data to write to the writebuffer
    CopyMemory abBuff(iOffset), ab(0), Len(sWrite)
 
    'set the filepointer to the first sector we want to write to
    SetFilePointer hDevice, iStartSec * BytesPerSector, 0, FILE_BEGIN
 
    'lock the drive for writing
    LockFile hDevice, LoWord(iStartSec * BytesPerSector), _
                      HiWord(iStartSec * BytesPerSector), _
                      LoWord(nSectors * BytesPerSector), _
                      HiWord(nSectors * BytesPerSector)
 
    'write it!
    DirectWriteDriveNT = WriteFile(hDevice, abBuff(0), UBound(abBuff) + 1, _
      nRead, 0&)
 
    'make sure everything was written
    FlushFileBuffers hDevice
 
    'unlock the drive
    UnlockFile hDevice, LoWord(iStartSec * BytesPerSector), _
                        HiWord(iStartSec * BytesPerSector), _
                        LoWord(nSectors * BytesPerSector), _
                        HiWord(nSectors * BytesPerSector)
 
    'and clean up a little bit
    CloseHandle hDevice
End Function
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
CD-Nr und Disk-Image834VBholic15.12.04 13:46
Re: CD-Nr und Disk-Image557Zero-G.15.12.04 13:51
Re: CD-Nr und Disk-Image523VBholic15.12.04 20:21
Re: CD-Nr und Disk-Image547Radeonmaster16.12.04 07:58
Re: CD-Nr und Disk-Image764Radeonmaster16.12.04 07:58
Re: CD-Nr und Disk-Image530Radeonmaster16.12.04 07:58
Re:CD-Nr und Disk-Image554VBholic16.12.04 16:29
Re:CD-Nr und Disk-Image756Radeonmaster16.12.04 16:55
Re:CD-Nr und Disk-Image559VBholic18.12.04 15:47
Re:CD-Nr und Disk-Image515VBholic19.12.04 19:14
Re:CD-Nr und Disk-Image570Radeonmaster20.12.04 17:23

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel