Burning CDs with the IMAPI2 Control - Burning the Disc
(Page 4 of 4 )
Set objDir = objFSI.Root
objDir.AddTree strPath, False
Next, you need to add a directory structure to the newly created disc image. The AddTree method accepts two parameters. The first parameter is a string indicating the path to the folder that contains the files to be burned. The second parameter is a Boolean value that indicates whether or not the folder itself should be included in the image or whether the image should just contain the folder’s subfolders and files.
Set objImage = objFSI.CreateResultImage()
Stream = objImage.ImageStream
Finally, the image needs to be created from the files provided using the CreateResultImage method. This is similar to saving an ISO image of the disc you are creating. Once the image is created, you can create a reference to the image stream. The image is not written to disc as a whole; instead, the image is streamed and written on piece at a time.
objImageWriter.Write(Stream)
Once you have an image stream, you can return to the ImageWriter object and start the actual burn process using the Write method. At this point, control will not return to your script until the burn process has completed.
The script that we’ve put together is just a basic example of what you can accomplish using the IMAPI2 control. There are several other methods available that can be used for error-checking as well as methods that can be used to further control the recorder by handling advanced settings such as write speed. For more information, check out the MSDN documentation for the IMAPI2 Reference.
Unfortunately, that’s all the space that I have for today. This should put you well on your way to writing scripts capable of burning data CDs using the IMAPI2 control. Don’t be afraid to play around with this script and see what you can accomplish. You may end up throwing away some CDs, but I think you’ll have some fun in the process. Until next time, keep coding!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |