Consulting

Results 1 to 9 of 9

Thread: Create CD's w/IMAPI2

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Create CD's w/IMAPI2

    I just scripted it, and it worked... I burned 449mg of data to CD. Adapted and modified from VBScript, but can work w/VBA [if IMAPI v2 is Installed].

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Code?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Oorang
    Code?
    problem is you were trashing AutoIT earlier

    point is, for functionality like this, one would [at least I would] not have to rely on macro code embedded in workbooks or mdb files, but rather callable as an exe, and maybe control Excel/Access from outside.

    When I said I scripted it, basically I took VbScript code and [in under 3 minutes] translated it to Winbatch, compiled as an EXE and tested. The Winbatch code could be translated to VBA in about the same time.

    Syntax, I've found, between these systems is minor Gerbil-Code as the COM portion is remarkably similar.

    Oh... I'm not trying to start a war, or Dis' anyone, especially you {since I have learned so much from your code}... below is the Winbatch script I posted on another board... I see it easily converted to VBA in minutes

    [vba]
    ;Winbatch 2007C - Using IMAPI2 to burn CD
    ;
    ;This example is for data and assumes all files are
    ;located in the same folder. Script is adapted from
    ;VbScript Code. Requires IMAPI v2 installed on PC available from MS
    ;[ http://www.microsoft.com/downloads/d...displaylang=en ]
    ;
    ;No error-handler included; Major Caveat: there is also no progress meter
    ;or messages, you need a recordable CD drive with a blank CD....but it did work
    ;
    ;Stan Littlefield, January 29, 2008
    ;//////////////////////////////////////////////////////////////////////////////////////////////

    ;Constants
    FsiFileSystemISO9660 = 1
    FsiFileSystemJoliet = 2
    FsiFileSystemUDF102 = 4
    nothing = ObjectType("DISPATCH",0)
    Path = "c:\burndir" ; location of files to transfer to disc
    ;Create Object and burn CD
    oDiscMaster = CreateObject("IMAPI2.MsftDiscMaster2")
    ForEach ID in oDiscMaster ;If you know the Drive ID/number, no need for the loop
    oRecorder=CreateObject("IMAPI2.MsftDiscRecorder2")
    oRecorder.InitializeDiscRecorder( ID )
    Next
    oFSI = CreateObject("IMAPI2FS.MsftFileSystemImage")
    cDir = oFSI.Root
    ;all Object set, burn it
    oDataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    oDataWriter.recorder = oRecorder
    oDataWriter.ClientName = "IMAPIv2 TEST"
    oFSI.ChooseImageDefaults(oRecorder)
    cDir.AddTree(Path,@FALSE)
    result = oFSI.CreateResultImage()
    oStream = result.ImageStream
    oDataWriter.write(oStream)
    oData=nothing
    oFSI=nothing
    oRecordset=nothing
    oDiscMaster=nothing
    Exit
    ;/////////////////////////////////////////////////////////////////////////////////////////////////////

    [/vba]

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    rofl Way harsh man I wasn't trashing AutoIT. I just said I think it makes more sense to my way of thinking just use already existing tools. Besides, you asked

    I like this code though

    (For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here.)
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Oorang
    For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here.)
    We know. We've marked your card
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Quote Originally Posted by Oorang
    For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here.)
    We know. We've marked your card
    rofl Well I'm an open minded guy. Explain to me it's merits over a standard language?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  7. #7
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Oorang
    rofl Well I'm an open minded guy. Explain to me it's merits over a standard language?
    The only advantage is getting the job done. For example, I want to perform several WMI tasks.... hmm... I write VBA macro code and store it in an Excel Workbook so I can call it to perform WMI.... and then I find that 95% of the code [COM stuff] could be placed in either Autoit or WB as a distributable exe], with about 5 minutes work [I'm slow, left-handed, so for most it is 3 minutes]...

    So I agree, you have the divine inspiration of "a standard language", otherwise the rest of us have to often pay the rent.

  8. #8
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    >> Not dissing AutoIT, just discussing <<

    Alright but there are several open source compilers (In fact full fledged IDEs) out there for C#, vb.net, C++. Why learn AutoIT, when you could teach your self a more mainstream language? (Note, I am not saying that it's not used because it is.) Is it easier to learn, better IDE, what is it's merit over say something like C# or vb.Net (both of which you run out of Sharp Develop for free as well)?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  9. #9
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Oorang
    >> Not dissing AutoIT, just discussing <<
    If you look at semi-languages like AutoIt, WB or even VBA there is that forecast future where they just won't cut it, so cutting one's teeth on say SharpDevelop makes sense.

    Back to IMAPI2: this snippet runs a media check. I don't see it as a major problem translating to VBA, I shook it out of VBScript in under 5 minutes using search and replace in Notepad.

    [vba]
    ;Winbatch 2007C - Using IMAPI2 to Test CD/DVD Media
    ;[ http://www.microsoft.com/downloads/d...displaylang=en ]
    ;
    ;Stan Littlefield, January 31, 2008
    ;//////////////////////////////////////////////////////////////////////////////////////////////

    ;NOTE: IMAPI Constants shortened to avoid WB var length conflict
    ; *** IMAPI2 Media Types
    TYPE_UNKNOWN = 0 ; Media not present OR is unrecognized
    TYPE_CDROM = 1 ; CD-ROM
    TYPE_CDR = 2 ; CD-R
    TYPE_CDRW = 3 ; CD-RW
    TYPE_DVDROM = 4 ; DVD-ROM
    TYPE_DVDRAM = 5 ; DVD-RAM
    TYPE_DVDPLUSR = 6 ; DVD+R
    TYPE_DVDPLUSRW = 7 ; DVD+RW
    TYPE_DVDPLUSR_DUALLAYER = 8 ; DVD+R dual layer
    TYPE_DVDDASHR = 9 ; DVD-R
    TYPE_DVDDASHRW = 10 ; DVD-RW
    TYPE_DVDDASHR_DUALLAYER = 11 ; DVD-R dual layer
    TYPE_DISK = 12 ; Randomly writable

    ; *** IMAPI2 Data Media States
    STATE_UNKNOWN = 0
    STATE_INFORMATIONAL_MASK = 15
    STATE_UNSUPPORTED_MASK = 61532 ;0xfc00
    STATE_OVERWRITE_ONLY = 1
    STATE_BLANK = 2
    STATE_APPENDABLE = 4
    STATE_FINAL_SESSION = 8
    STATE_DAMAGED = 1024 ;0x400
    STATE_ERASE_REQUIRED = 2048 ;0x800
    STATE_NON_EMPTY_SESSION = 4096 ;0x1000
    STATE_WRITE_PROTECTED = 8192 ;0x2000
    STATE_FINALIZED = 16384 ;0x4000
    STATE_UNSUPPORTED_MEDIA = 32768 ;0x8000

    nothing = ObjectType("DISPATCH",0)
    cOut=""
    ;Create Needed Objects
    oDiscMaster = CreateObject("IMAPI2.MsftDiscMaster2")
    ForEach ID in oDiscMaster ;If you know the Drive ID/number, no need for the loop
    oRecorder=CreateObject("IMAPI2.MsftDiscRecorder2")
    oRecorder.InitializeDiscRecorder( ID )
    Next
    oDataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    oDataWriter.recorder = oRecorder
    If oDataWriter.IsRecorderSupported(oRecorder)
    cOut=cOut:"--- Current recorder IS supported. ---":@CRLF
    Else
    cOut=cOut:"Current recorder IS NOT supported.":@CRLF
    Endif
    If oDataWriter.IsCurrentMediaSupported(oRecorder)
    cOut=cOut:"--- Current media IS supported. ---":@CRLF
    Else
    cOut=cOut:"Current media IS NOT supported.":@CRLF
    Endif
    cOut=cOut:"ClientName = ":oDataWriter.ClientName:@CRLF:@CRLF:"Current Media State":@CRLF
    cState=oDataWriter.CurrentMediaStatus
    If STATE_UNKNOWN & cState
    cOut=cOut:" Media state is unknown.":@CRLF
    Endif
    If STATE_OVERWRITE_ONLY & cState
    cOut=cOut:" Currently, only overwriting is supported.":@CRLF
    Endif

    If STATE_APPENDABLE & cState
    cOut=cOut:" Media is currently appendable.":@CRLF
    Endif

    If STATE_FINAL_SESSION & cState
    cOut=cOut:" Media is in final writing session.":@CRLF
    Endif

    If STATE_DAMAGED & cState
    cOut=cOut:" Media is damaged.":@CRLF
    Endif
    cOut=cOut:@CRLF:"Current Media Type":@CRLF
    mediaType = oDataWriter.CurrentPhysicalMediaType
    Select mediaType
    Case TYPE_UNKNOWN
    cOut=cOut:" Empty device or an unknown disc type.":@CRLF
    Break
    Case TYPE_CDROM
    cOut=cOut:" CD-ROM":@CRLF
    Break
    Case TYPE_CDR
    cOut=cOut:" CD-R":@CRLF
    Break
    Case TYPE_CDRW
    cOut=cOut:" CD-RW":@CRLF
    Break
    Case TYPE_DVDROM
    cOut=cOut:" Read-only DVD drive and/or disc":@CRLF
    Break
    Case TYPE_DVDRAM
    cOut=cOut:" DVD-RAM":@CRLF
    Break
    Case TYPE_DVDPLUSR
    cOut=cOut:" DVD+R":@CRLF
    Break
    Case TYPE_DVDPLUSRW
    cOut=cOut:" DVD+RW":@CRLF
    Break
    Case TYPE_DVDPLUSR_DUALLAYER
    cOut=cOut:" DVD+R Dual Layer media":@CRLF
    Break
    Case TYPE_DVDDASHR
    cOut=cOut:" DVD-R":@CRLF
    Break
    Case TYPE_DVDDASHRW
    cOut=cOut:" DVD-RW":@CRLF
    Break
    Case TYPE_DVDDASHR_DUALLAYER
    cOut=cOut:" DVD-R Dual Layer media":@CRLF
    Break
    Case TYPE_DISK
    cOut=cOut:" Randomly-writable, hardware-defect managed media type ":@CRLF
    cOut=cOut:" that reports the 'Disc' profile as current.":@CRLF
    EndSelect
    oData=nothing
    oRecordset=nothing
    oDiscMaster=nothing
    Message("Recordable Device",cOut)
    Exit
    ;/////////////////////////////////////////////////////////////////////////////////////////////////////
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •