Solved

Translate vb script to vb 6 for windows imapi2 code

Posted on 2010-09-08
10
773 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:eneate
  • 6
  • 4
10 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 33632997
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

0
 

Author Comment

by:eneate
ID: 33634577
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??
0
 

Author Comment

by:eneate
ID: 33634635
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??
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 65

Expert Comment

by:RobSampson
ID: 33642707
Hi, looks like that could be
Dim Dir as iFsiDirectoryItem

Regards,

Rob.
0
 

Author Comment

by:eneate
ID: 33650609
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
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 33651765
Hi, not sure if you've done this yet, but make sure you have done the following:
1. Right click on the VB project
2. Select "Add Reference" menu item
3. Select the "COM" tab in the "Add Reference" dialog
4. Select "Microsoft IMAPI2 Base Functionality" component
5. Click OK

I have made a couple of changes as suggested here, but it's a bit hard to follow:
http://social.msdn.microsoft.com/Forums/en-US/windowsopticalplatform/thread/559fa254-3186-4bfe-b813-6870688237d6

Regards,

Rob.
Dim Index                ' Index to recording drive.
    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.
 	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(dataWriter.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

Open in new window

0
 

Author Comment

by:eneate
ID: 33656911
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

0
 

Author Comment

by:eneate
ID: 33657241
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
0
 

Author Closing Comment

by:eneate
ID: 33657245
Thanks again
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33658966
Fantastic. Thanks for posting your final code too.

Regards,

Rob.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…

856 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