Link to home
Start Free TrialLog in
Avatar of eneate
eneateFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Translate vb script to vb 6 for windows imapi2 code

Hi

Can anyone help me to translate some vb script into vb 6. I have worked through some but it is not quite right. I have attached the original vb script code below
Thanks
' *** 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

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, try this.  I can't test it because I don't have VB.

Regards,

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

Call 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 = New IMAPI2.MsftDiscMaster2

    ' Create a DiscRecorder object for the specified burning device.
    Dim uniqueId
    Set Recorder = New 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 = New IMAPI2FS.MsftFileSystemImage
    Set Dir = FSI.Root

    'Create the new disc format and set the recorder
    Set dataWriter = New 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

Open in new window

Avatar of eneate

ASKER

Hi
Thanks for the feedback, i get a type mismatch error on this line

FSI.ChooseImageDefaults (Recorder)

also when i type fsi when i add the dot option should appear but nothing does so i suspect i need to dec;lare this as something but i am not sure what??
Avatar of eneate

ASKER

I think part of the problem is the declaration of the variables, if i add the following

Dim FSI As MsftFileSystemImage           ' Disc file system
    Dim Dir                ' Root directory of the disc file system
    Dim dataWriter As MsftDiscFormat2Data

fsi and datawriter now appear to work i am not sure what to declare dir as??
Hi, looks like that could be
Dim Dir as iFsiDirectoryItem

Regards,

Rob.
Avatar of eneate

ASKER

Hi

This is whta i have so far

    Dim Index                ' Index to recording drive.
    Dim Recorder    As MsftDiscRecorder2         ' 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 DiscMaster        As MsftDiscMaster2
    Set DiscMaster = New IMAPI2.MsftDiscMaster2

    ' Create a DiscRecorder object for the specified burning device.
 
    Set Recorder = New MsftDiscRecorder2
 
    Recorder.InitializeDiscRecorder DiscMaster.Item(0)

    ' Create an image stream for a specified directory.
    Dim FSI As MsftFileSystemImage           ' Disc file system
    Dim Dir      As IFsiDirectoryItem          ' Root directory of the disc file system
    Dim dataWriter As MsftDiscFormat2Data
       
    ' Create a new file system image and retrieve root directory
    Set FSI = New MsftFileSystemImage
    Set Dir = FSI.Root
   
    'Create the new disc format and set the recorder
    Set dataWriter = New 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

in this format fsi.chooseimagedefdaults returns a type mismatch error, if i change the decelation to just dim reorder it gets to the dir.addtree line and generates a system can not find the specified path error.

When the recorder is not specifically defined after typing recorder. nothing appears as options but when it is declared the options appear so it it correct to only define without a spewcific option??

Thanks
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eneate

ASKER

Hi
Thanks for the feedback, yes i have added the reference. Using the code below it gets as far as stream = result.imagestream and here genertaes a type mismatch error. Also when you type result. nothing appear after result. The drive it initialising, i can get the drive to open recognise the type of disc but not actually write anything. It feels nearly there ........ ;-)
Public Function t_cd()


Dim Index                ' Index to recording drive.
    Dim Path         As String        ' Directory of files to burn
    Dim Stream             ' Data stream for burning device
    
    Index = 1                ' Second drive on the system
    Path = "c:\bob freeman"      ' Files to transfer to disc

    ' Create a DiscMaster2 object to connect to optical drives.
  Dim DiscMaster        As MsftDiscMaster2
    Set DiscMaster = New IMAPI2.MsftDiscMaster2

    ' Create a DiscRecorder object for the specified burning device.
    Dim Recorder 'As MsftDiscRecorder2
    Set Recorder = New MsftDiscRecorder2
  
    Recorder.InitializeDiscRecorder DiscMaster.Item(0)

    ' Create an image stream for a specified directory.
    Dim FSI As MsftFileSystemImage           ' Disc file system
    Dim Dir      As IFsiDirectoryItem          ' Root directory of the disc file system
    Dim dataWriter As MsftDiscFormat2Data
        
    ' Create a new file system image and retrieve root directory
    Set FSI = New MsftFileSystemImage
    Set Dir = FSI.Root
    
    'Create the new disc format and set the recorder
    Set dataWriter = New IMAPI2.MsftDiscFormat2Data
    dataWriter.Recorder = Recorder
    dataWriter.ClientName = "IMAPIv2 TEST"
    
        'FSI.ChooseImageDefaults (Recorder)
        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.
    Debug.Print "Writing content to disc..."
    dataWriter.Write (Stream)

    Debug.Print "----- Finished writing content -----"
    Main = 0

End Function

Open in new window

Avatar of eneate

ASKER

Hi
finally i have it working just a few changes, i was helped a lot by usiong the link to the msn that you sent through, here is the final code that i used to write data with imapi2

Function BurnDataDisc()   '(rnIndex As Integer, _
                      rsPath As String) As Boolean

  Dim objFSI As MsftFileSystemImage
  Dim objDir As IFsiDirectoryItem
  Dim volumn_name As String
  Dim objResult As Object
  Dim objStream As MsftStreamZero
  Dim rspath As String
  Dim dataWriter As MsftDiscFormat2Data
   
  rspath = "c:\bob freeman"
 
  'check that the user has entered a name for the disc, if none is found generate
  'an error message and exit the function
  '********************************************************************************************
 
  volumn_name = frmmain.txtdiscname.Text
 
  If volumn_name = "" Then
  MsgBox "Please enter a name for your CD/DVD disc, then try again", vbSystemModal + vbInformation + vbOKOnly, "CERA - Disc Burn"
    Exit Function
      End If
     
      '*****************************************************************************************************************
   
  ' Create a DiscMaster2 object to connect to optical drives.
  Dim DiscMaster        As MsftDiscMaster2
    Set DiscMaster = New IMAPI2.MsftDiscMaster2

    ' Create a DiscRecorder object for the specified burning device.
    Dim Recorder 'As MsftDiscRecorder2
    Set Recorder = New MsftDiscRecorder2
 
    Recorder.InitializeDiscRecorder DiscMaster.Item(0) 'initialise the default writer
         
    'Create the new disc format and set the recorder
    Set dataWriter = New IMAPI2.MsftDiscFormat2Data
    dataWriter.Recorder = Recorder
    dataWriter.ClientName = "Consolite CERA"

  'Create the File System object
  Set objFSI = New MsftFileSystemImage

  'Add the data
  Set objDir = objFSI.Root
  objDir.AddTree rspath, True
         
  'Create the File System image
  Debug.Print "Writing to disc..."
  Set objResult = objFSI.CreateResultImage()
  Set objStream = objResult.ImageStream
 
  'make sure that the disc will be finalized
 
  Set dataWriter.ForceMediaToBeClosed = True
 
  'Write to the disc
 
  frmmain.sbr1.Panels(1).Text = "Data is writing to the disc"
  Debug.Print "Writing to disc..."
   dataWriter.Write objStream
   
   frmmain.sbr1.Panels(1).Text = "Disc has been written successfully"
 
  Debug.Print "Done"
 
  BurnDataDisc = True

Thanks
Avatar of eneate

ASKER

Thanks again
Fantastic. Thanks for posting your final code too.

Regards,

Rob.