Go Premium for a chance to win a PS4. Enter to Win


VB.Net Create ISO File

Posted on 2009-07-07
Medium Priority
Last Modified: 2014-03-24
Hello guys,

I am trying to determine how to save an ISO file of a CD image, though VB.Net...  My goal is to have a system to backup CD's and DVD's (Data, not movie) to our server here at work, and another a way to burn them back down to media if needed.

We run a shop where we fix a lot of computers - and want to make a vault of the 'Recovery Disks' provided with some systems.  After I can get the DVD -> ISO and ISO -> DVD (or CD) working, I will implement a feature to look for manufacture, model, etc.

Any idea's on the first part, Creating the ISO?  I would like to have a status bar as well - killing my original thought of a command-line background process...

Thanks for any solutions - sample code, please.

Question by:Crazy_Penguins
  • 3
  • 3
LVL 29

Expert Comment

ID: 24800971
<<  am trying to determine how to save an ISO file of a CD image >>

If you already have the CD that contains the image you just open the volume for direct access and read it like any normal file and save it as .ISO extension.

Here is how you can do this using API: (note: You will need admin privileges)

1) Open the cd volume for direct access. Use these flags below for cdrom. (e: would be the CDROM letter)
hDevice = CreateFileW("\\?\e:", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
2) Create a new file that you will write the image to. Use flags below.
3) Signals the file system driver not to perform any I/O boundary checks on partition read or write calls.
DeviceIoControl(hDevice, FSCTL_ALLOW_EXTENDED_DASD_IO, 0, 0, 0, 0, dwBytes, 0)

4)Just read the device like a regular file. Make sure to read the file in chunks a good buffer size would be 64KB.

ReadFile(hDevice, Buffer, BufferSize, dwRead, 0)
WriteFile(hFile, ByVal Buffer, dwRead, dwWritten, 0)

5)When your done reading and writing from the device finish by flushing the file and closing the handles.

Call FlushFileBuffers(hDevice)
LVL 29

Expert Comment

ID: 24800982
' Handle to the file you created NOT the device handle like is shown in the above example. Can't belive I missed that before posting.
Should be:
Call FlushFileBuffers(hFile)

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 24801476
I will give this a better look in the morning, but to be sure we are on the same page, this will allow me to make an ISO image of the disk, correct?  Almost read like perhaps I did not state this well enough, but again I will look at your sample in the morning.

Thank you,
LVL 29

Accepted Solution

nffvrxqgrcfqvvc earned 2000 total points
ID: 24801658
Yes. Funny you say that does it sound to easy to be true? :) if you already have a CD-ROM with data on it than what I mentioned above will create the exact image. I did this awhile back and managed to find the code I wrote in my backup although in VB6. Convert it to .NET or you can have someone convert it for you.

You should also visit this website from microsoft and use there tool. This will let you map the image to a drive letter. You can use it for testing or do what you like with it.
Virtual CD-ROM Control Panel
Option Explicit
' Author's Name
' Exact Copy CDROM
Private Const INVALID_HANDLE_VALUE As Long = (-1)
Private Const FSCTL_ALLOW_EXTENDED_DASD_<wbr ></wbr>IO As Long = &H90083
Private Const FILE_FLAG_BACKUP_SEMANTICS<wbr ></wbr> As Long = &H2000000
Private Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
Private Const FILE_FLAG_NO_BUFFERING As Long = &H20000000
Private Const FILE_SHARE_READ As Long = &H1
Private Const OPEN_EXISTING As Long = 3
Private Const CREATE_ALWAYS As Long = 2
Private Const GENERIC_READ As Long = &H80000000
Private Const GENERIC_WRITE As Long = &H40000000
Private Const DRIVE_CDROM As Long = 5
Private Declare Function CreateFileW Lib "kernel32" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, ByVal lpInBuffer As Long, ByVal nInBufferSize As Long, ByVal lpOutBuffer As Long, ByVal nOutBufferSize As Long, ByRef lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetDriveTypeW Lib "kernel32" (ByVal lpRootPathName As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Dim bAbort As Boolean
Public Sub AbortWrite()
' Should be able to abort a write in progress.
bAbort = True
End Sub
Public Sub WriteImage(ByVal Device As String, ByVal SaveAs As String)
' Device: The device drive letter or volume guid. e:
' SaveAs: The location of the file being created. d:\dummy.iso
' Multiple of sectore size 2,048 bytes for CD-ROMs.
' (2048 * 32)
Dim Buffer(65536 - 1) As Byte
Dim cbBogus As Long
Dim cbRead As Long
Dim cbWritten As Long
Dim hDevice As Long
Dim hFile As Long
' Set abort flags.
bAbort = False
' Should check if this is a valid CD-ROM device.
If GetDriveTypeW(StrPtr(Devic<wbr ></wbr>e & "\")) <> DRIVE_CDROM Then
  ' Failed CDROM checksum.
  Exit Sub
End If
' Open the volume/device for direct access (DASD)
hDevice = CreateFileW(StrPtr("\\.\" & Device), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS<wbr ></wbr>, 0)
  ' Failed on accessing the volume handle.
  Exit Sub
End If
' Create a new file with restricted access. FILE_FLAG_NO_BUFFERING flag as a replacement for calling the FlushFileBuffers
  ' Failed creating file to write image.
  CloseHandle hDevice
  Exit Sub
End If
' Signals the file system driver not to perform any I/O boundary checks on partition read or write calls.
' Allows access to hidden sectors, a part of the partition that might exist between the first sector of
' the partition (the boot parameter block) and the first useful sector of the partition.
Call DeviceIoControl(hDevice, FSCTL_ALLOW_EXTENDED_DASD_<wbr ></wbr>IO, 0, 0, 0, 0, cbBogus, 0)
' Read/Write the image.
Debug.Print "Write Begin: " & Time
  If ReadFile(hDevice, Buffer(0), 65536, cbRead, 0) Then
    Call WriteFile(hFile, Buffer(0), cbRead, cbWritten, 0)
    Exit Do
  End If
  ' User wants to abort.
  If bAbort = True Then Exit Do
Loop Until cbRead = 0
' Check if user aborted or write finished.
If bAbort = True Then
  Debug.Print "Abort!"
  Debug.Print "Write End: " & Time
End If
' Cleanup
CloseHandle hDevice
CloseHandle hFile
Erase Buffer
End Sub

Open in new window


Author Closing Comment

ID: 31600821

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question