eneate
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
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
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??
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??
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??
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.
Dim Dir as iFsiDirectoryItem
Regards,
Rob.
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.InitializeDiscRec order 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
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.InitializeDiscRec
' 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ........ ;-)
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
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.InitializeDiscRec order 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.ForceMediaToBeC losed = True
'Write to the disc
frmmain.sbr1.Panels(1).Tex t = "Data is writing to the disc"
Debug.Print "Writing to disc..."
dataWriter.Write objStream
frmmain.sbr1.Panels(1).Tex t = "Disc has been written successfully"
Debug.Print "Done"
BurnDataDisc = True
Thanks
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.InitializeDiscRec
'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.ForceMediaToBeC
'Write to the disc
frmmain.sbr1.Panels(1).Tex
Debug.Print "Writing to disc..."
dataWriter.Write objStream
frmmain.sbr1.Panels(1).Tex
Debug.Print "Done"
BurnDataDisc = True
Thanks
ASKER
Thanks again
Fantastic. Thanks for posting your final code too.
Regards,
Rob.
Regards,
Rob.
Regards,
Rob.
Open in new window