none
Creating ISO files with vbscript possible???

    Question

  •  

    I've written vbscripts for most of the tasks that I need with IMAPIv2. I am also very happy using IsoImageManager, after installing the Feature Pack. But I am still unable to create ISO files.

     

    After spending days searching the Internet, including many posts on this forum, I've seen many examples for C++ and other languages, but there is not one working vbscript that creates ISO files.

     

    My script returns runtime error: Object required, when calling CopyTo or Stat or anything else on Stream object. From information that I could find on the Internet, it seems that IStream is not an automation object and therefore this method doesn't work in vbscript.

     

    So, is it at all possible to write a vbscript that creates ISO files, without rocket science involved (IStream wrapper or whatever)? If not at the moment, will this be added in the future?

     

    Wednesday, November 12, 2008 10:24 AM

Answers

  • Usually binary files are handled in vbscript through an ADODB.Stream object, unfortunately the ADODB Write method expects a byte array and not an IStream object as provided by IMAPI, so the solution still needs the rocket science wrapper for IStream, the shlwapi.dll solution pointed by David works for .net but vbscript needs a COM object that supports automation (ActiveX) to handle it, you can write your own C++ ATL or MFC project..... or you can use one of the currently available on internet (at your own risk), I will use this freeware: http://www.newobjects.com/product.asp?ID=63 and here is my sample code:

     

    Option Explicit

    ' *** CD/DVD disc file system types
    Const FsiFileSystemNone     = 0
    Const FsiFileSystemISO9660  = 1
    Const FsiFileSystemJoliet   = 2
    Const FsiFileSystemUDF      = 4       
    Const FsiFileSystemUnknown  = 1073741824

    ' *** Media Physical Type Enumeration
    Const IMAPI_MEDIA_TYPE_DISK = 12

    WScript.Quit(Main)

    Function Main    
        Dim FSI                         ' Disc file system
        Dim InputStream                 ' Data stream for the image
        Dim OutputStream                ' Output file stream
        Dim SourceDirectory             ' Input directory
        Dim VolumeName
        Dim OutputIsoName
        Dim ResultImage
        Dim ImageSize
        Dim WrittenBytes
        Dim sf
       
        SourceDirectory = "C:\Test"        
        VolumeName = "MyVolume"
        OutputIsoName = "MyImage.iso"
           
        ' Create a new file system image and retrieve root directory       
        Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")
        FSI.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_TYPE_DISK)
        FSI.FileSystemsToCreate = FsiFileSystemJoliet + FsiFileSystemISO9660
        FSI.VolumeName = VolumeName
        FSI.Root.AddTree SourceDirectory, false '(string sourceDir, bool includeBaseDir)
                
        ' Create the Image and pass the IMAPI.IStream to an object that supports IStream
        Set ResultImage = FSI.CreateResultImage()
        Set InputStream = CreateObject("newObjects.utilctls.SFStream")
        InputStream.SetStream(ResultImage.ImageStream)

        ' Create the output file and write the stream

        Set sf = CreateObject("newObjects.utilctls.SFMain") 'here you can use ADODB instead
        Set OutputStream = sf.CreateFile(OutputIsoName)
        ImageSize = InputStream.Size   
        WrittenBytes = OutputStream.WriteBin(InputStream.ReadBin(ImageSize))
        OutputStream.close
        WScript.Echo "----- Image Size    : ", ImageSize
        WScript.Echo "----- Written Bytes : ", WrittenBytes  
        WScript.Echo "----- Finished writing content -----"

        Main = 0
    End Function

     

    Seems that the newObjects wrapper only works on 32 bits, let me know if you find another way...

    I hope this helps Santa

    Wednesday, December 3, 2008 8:13 AM

All replies

  • I see another developer doing this:

     

    using System.Runtime.InteropServices;
    using System.Runtime.InteropServices.ComTypes;
    using IMAPI2.Interop;

    Import this legacy Win32API...

     
    [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
    static internal extern uint SHCreateStreamOnFile
        (string pszFile, uint grfMode, out IStream ppstm);

    in managed code

     

    http://www.codeproject.com/KB/miscctrl/ISOImage.aspx

     

    Is this usable for your VBscript?

     

    Friday, November 14, 2008 12:21 AM
  • Thank you for your reply.

     

    I've seen that solution before, but the problem is: it's written in C#, and I don't know how to translate it into VBscript. So, I'm not sure if it would work in VBscript.

     

    Anyone out there who can translate this code from C# to VBscript?

     

     

    Monday, November 17, 2008 5:09 AM
  • Usually binary files are handled in vbscript through an ADODB.Stream object, unfortunately the ADODB Write method expects a byte array and not an IStream object as provided by IMAPI, so the solution still needs the rocket science wrapper for IStream, the shlwapi.dll solution pointed by David works for .net but vbscript needs a COM object that supports automation (ActiveX) to handle it, you can write your own C++ ATL or MFC project..... or you can use one of the currently available on internet (at your own risk), I will use this freeware: http://www.newobjects.com/product.asp?ID=63 and here is my sample code:

     

    Option Explicit

    ' *** CD/DVD disc file system types
    Const FsiFileSystemNone     = 0
    Const FsiFileSystemISO9660  = 1
    Const FsiFileSystemJoliet   = 2
    Const FsiFileSystemUDF      = 4       
    Const FsiFileSystemUnknown  = 1073741824

    ' *** Media Physical Type Enumeration
    Const IMAPI_MEDIA_TYPE_DISK = 12

    WScript.Quit(Main)

    Function Main    
        Dim FSI                         ' Disc file system
        Dim InputStream                 ' Data stream for the image
        Dim OutputStream                ' Output file stream
        Dim SourceDirectory             ' Input directory
        Dim VolumeName
        Dim OutputIsoName
        Dim ResultImage
        Dim ImageSize
        Dim WrittenBytes
        Dim sf
       
        SourceDirectory = "C:\Test"        
        VolumeName = "MyVolume"
        OutputIsoName = "MyImage.iso"
           
        ' Create a new file system image and retrieve root directory       
        Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")
        FSI.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_TYPE_DISK)
        FSI.FileSystemsToCreate = FsiFileSystemJoliet + FsiFileSystemISO9660
        FSI.VolumeName = VolumeName
        FSI.Root.AddTree SourceDirectory, false '(string sourceDir, bool includeBaseDir)
                
        ' Create the Image and pass the IMAPI.IStream to an object that supports IStream
        Set ResultImage = FSI.CreateResultImage()
        Set InputStream = CreateObject("newObjects.utilctls.SFStream")
        InputStream.SetStream(ResultImage.ImageStream)

        ' Create the output file and write the stream

        Set sf = CreateObject("newObjects.utilctls.SFMain") 'here you can use ADODB instead
        Set OutputStream = sf.CreateFile(OutputIsoName)
        ImageSize = InputStream.Size   
        WrittenBytes = OutputStream.WriteBin(InputStream.ReadBin(ImageSize))
        OutputStream.close
        WScript.Echo "----- Image Size    : ", ImageSize
        WScript.Echo "----- Written Bytes : ", WrittenBytes  
        WScript.Echo "----- Finished writing content -----"

        Main = 0
    End Function

     

    Seems that the newObjects wrapper only works on 32 bits, let me know if you find another way...

    I hope this helps Santa

    Wednesday, December 3, 2008 8:13 AM
  •  

    Thank you for the help.
    Thursday, December 4, 2008 9:10 AM
  • Miguel, thank you very much. This is the first working script that I've seen. I've tested it and it works well.

    I've noticed a problem with file/folder time attributes, but then I checked burning directly to a CD, without using ISO files, and it was the same, so I'll post it separately.

    Thank you David, too. If there is a wish list, I would like to see this functionality added to future IMAPI2 releases, so that there is no need for third party ActiveX.

    Mary Christmas and Happy New Year to all.

     

    Saturday, December 13, 2008 11:23 AM