Solved

Translate vb script to vb 6 for windows imapi2 code

Posted on 2010-09-08
10
758 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Hi, looks like that could be
Dim Dir as iFsiDirectoryItem

Regards,

Rob.
0
 

Author Comment

by:eneate
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks again
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Fantastic. Thanks for posting your final code too.

Regards,

Rob.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now