共用方式為


燒錄光碟映像

使用 IMAPI 刻錄光碟的步驟如下:

  1. 建構檔系統映像,其中包含要寫入光碟的目錄和檔案。
  2. 設定光碟錄製器 與光學設備通訊。
  3. 建立數據寫入器 並將影像燒毀至光碟。

如需燒毀光碟映射的範例,請參閱 VBScript 範例

建構燒錄映像

燒毀影像是準備寫入光學媒體的數據流。 ISO9660、Joliet 和 UDF 格式的燒毀映像是由個別檔案和目錄的檔案系統所組成。 CFileSystemImage 物件是保留要放在光學媒體上的檔案和目錄的文件系統物件。 IFileSystemImage 介面可讓您存取檔案系統對象和設定。

建立文件系統對象之後,請分別呼叫 IFileSystemImage::CreateFileItemIFileSystemImage::CreateDirectoryItem 方法來建立檔案和目錄物件。 檔案和目錄物件可用來提供檔案和目錄的特定詳細數據。 可用於 IFileSystemImage 的事件處理程式方法 可以識別要新增至文件系統映像的目前檔案、已複製的扇區數目,以及要複製的扇區總數。

或者,您可以使用 IFileSystemImage::put_BootImageOptions 屬性,將開機映像附加至檔案系統。 如需範例,請參閱 新增開機映像

最後,呼叫 IFileSystemImage::CreateResultImage 來建立數據流,並透過 IFileSystemImageResult提供存取權。 然後,可以將新的數據流直接提供給 IDiscFormat2Data::Write 方法,或儲存至檔案以供日後使用。

設定光碟錄製器

MsftDiscMaster2 物件會提供系統上光學裝置的列舉。 IDiscMaster2 介面可讓您存取產生的裝置列舉。 檢查列表以找出適當的錄音裝置。 MsftDiscMaster2 物件也會在電腦新增或刪除光學設備時提供事件通知。

尋找光學錄製器並擷取其標識符之後,請建立 MsftDiscRecorder2 物件,並使用裝置識別碼初始化錄製器。 IDiscRecorder2 介面可讓您存取錄製器物件,以及一些基本裝置資訊,例如廠商標識碼、產品標識碼、產品修訂,以及退出媒體並關閉匣的方法。

建立數據寫入器並寫入燒毀映像

MsftDiscFormat2Data 物件會提供寫入方法、寫入函式和媒體特定屬性的相關屬性。 IDiscFormat2Data 介面可讓您存取 MsftDiscFormat2Data 物件。

光碟錄製器會使用 IDiscFormat2Data::put_Recorder 屬性連結到格式寫入器。 在錄製器系結至格式寫入器之後,您可以使用 IDiscFormat2Data::Write 方法,先執行媒體的相關查詢,並更新寫入特定屬性,再將結果影像寫入光碟。

IMAPI 所提供的其他格式寫入介面的運作方式類似:其他格式寫入介面包括:

注意

電源狀態轉換有可能在燒毀作業期間進行(也就是使用者註銷或系統暫停),這會導致燒毀程式中斷和可能的數據遺失。 如需程式設計考慮,請參閱 防止在燒毀期間註銷或暫停

 

VBScript 範例

此腳本範例示範如何使用 IMAPI 對象來燃燒光學媒體;更具體地說,將目錄寫入空白光碟。程式代碼不包含錯誤檢查,並假設下列事項:

  • 系統上已安裝相容的光碟裝置。
  • 光碟裝置是系統上的第二個磁碟驅動器。
  • 相容的光碟會插入光碟裝置中。
  • 光碟是空白的。
  • 要寫入光碟的檔案位於 「g:\burndir」。。

其他功能,例如錯誤檢查、裝置和媒體相容性、事件通知,以及計算光碟上的可用空間,都可以新增至此腳本。

' This script burns data files to disc in a single session 
' using files from a single directory tree.
 
' Copyright (C) Microsoft Corp. 2006

Option Explicit

' *** CD/DVD disc file system types
Const FsiFileSystemISO9660 = 1
Const FsiFileSystemJoliet  = 2
Const FsiFileSystemUDF102  = 4

WScript.Quit(Main)

Function Main
    Dim Index                ' Index to recording drive.
    Dim Recorder             ' Recorder object
    Dim Path                 ' Directory of files to burn
    Dim Stream               ' Data stream for burning device
    
    Index = 1                ' Second drive on the system
    Path = "g:\BurnDir"      ' Files to transfer to disc

    ' Create a DiscMaster2 object to connect to optical drives.
    Dim g_DiscMaster
    Set g_DiscMaster = WScript.CreateObject("IMAPI2.MsftDiscMaster2")

    ' Create a DiscRecorder object for the specified burning device.
    Dim uniqueId
    set recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
    uniqueId = g_DiscMaster.Item(index)
    recorder.InitializeDiscRecorder( uniqueId )

    ' Create an image stream for a specified directory.
    Dim FSI                  ' Disc file system
    Dim Dir                  ' Root directory of the disc file system
    Dim dataWriter    
        
    ' Create a new file system image and retrieve root directory
    Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")
    Set Dir = FSI.Root

    'Create the new disc format and set the recorder
    Set dataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    dataWriter.recorder = Recorder
    dataWriter.ClientName = "IMAPIv2 TEST"

    FSI.ChooseImageDefaults(recorder)
        
    ' Add the directory and its contents to the file system 
    Dir.AddTree Path, false
        
    ' Create an image from the file system
    Dim result
    Set result = FSI.CreateResultImage()
    Stream = result.ImageStream
    
    ' Write stream to disc using the specified recorder.
    WScript.Echo "Writing content to disc..."
    dataWriter.write(Stream)

    WScript.Echo "----- Finished writing content -----"
    Main = 0
End Function

使用 IMAPI

IDiscFormat2Data

IDiscFormat2Erase

IDiscFormat2RawCD

IDiscFormat2TrackAtOnce

IDiscMaster2

IDiscRecorder2

IFileSystemImage

IStream