Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create and Burn CDs/DVDs Using IMAPI on Windows

The Image Mastering API (IMAPI) is a crucial component in the Windows operating system that allows users to create and burn CDs and DVDs. IMAPI provides a standardized way to interact with optical media devices, making it easier for developers to integrate disc burning capabilities into their applications. This article will guide you through the steps to use IMAPI for creating and burning discs on Windows, highlighting its importance and providing practical examples.

Examples:

  1. Using IMAPI via Command Line:

    To burn a CD or DVD using IMAPI from the command line, you can use the IMAPI2 command-line tool. Below is an example of how to burn an ISO image to a disc.

    IMAPI2 burn -source "C:\path\to\your\file.iso" -target "D:"

    This command specifies the source ISO file and the target drive (usually the letter of your CD/DVD drive).

  2. Burning a Disc Using PowerShell:

    PowerShell provides a more versatile way to interact with IMAPI. Below is a script that demonstrates how to burn files to a CD/DVD.

    # Load the IMAPI COM object
    $IMAPI = New-Object -ComObject IMAPI2FS.MsftFileSystemImage
    
    # Set the volume name
    $IMAPI.VolumeName = "MyDisc"
    
    # Add files to the image
    $IMAPI.Root.AddTree("C:\path\to\your\files", $false)
    
    # Create the result stream
    $result = $IMAPI.CreateResultImage()
    
    # Get the disc recorder
    $recorder = New-Object -ComObject IMAPI2.MsftDiscRecorder2
    $recorder.InitializeDiscRecorder("D:")
    
    # Burn the image
    $burner = New-Object -ComObject IMAPI2.MsftDiscFormat2Data
    $burner.Recorder = $recorder
    $burner.ClientName = "MyBurningApp"
    $burner.Write($result.ImageStream)

    This script initializes the IMAPI COM object, sets the volume name, adds files to the image, and then burns the image to the disc.

  3. Using IMAPI in a C# Application:

    For developers who want to integrate disc burning capabilities into their C# applications, here is a simple example.

    using System;
    using IMAPI2.Interop;
    
    class Program
    {
       static void Main(string[] args)
       {
           MsftFileSystemImage fileSystemImage = new MsftFileSystemImage();
           fileSystemImage.VolumeName = "MyDisc";
           fileSystemImage.Root.AddTree(@"C:\path\to\your\files", false);
    
           IFileSystemImageResult result = fileSystemImage.CreateResultImage();
    
           MsftDiscRecorder2 discRecorder = new MsftDiscRecorder2();
           discRecorder.InitializeDiscRecorder("D:");
    
           MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data();
           discFormatData.Recorder = discRecorder;
           discFormatData.ClientName = "MyBurningApp";
           discFormatData.Write(result.ImageStream);
       }
    }

    This C# code initializes the IMAPI objects, sets up the file system image, and writes it to the disc.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.