PDA

View Full Version : Create CD's w/IMAPI2



stanl
01-29-2008, 02:36 PM
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].

Oorang
01-30-2008, 12:17 PM
Code?

stanl
01-31-2008, 06:31 AM
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: pray2:


;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/details.aspx?FamilyId=B5F726F1-4ACE-455D-BAD7-ABC4DD2F147B&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
;/////////////////////////////////////////////////////////////////////////////////////////////////////

Oorang
01-31-2008, 08:02 AM
rofl Way harsh man:whyme: 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:rolleyes:

I like this code though:)

(For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here (http://www.vbaexpress.com/forum/showthread.php?t=16994).)

Bob Phillips
01-31-2008, 08:12 AM
For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here (http://www.vbaexpress.com/forum/showthread.php?t=16994).)

We know. We've marked your card :D

Oorang
01-31-2008, 08:40 AM
For people who are not Stan or Me he is referring to the blasphemy I uttered against AutoIT here (http://www.vbaexpress.com/forum/showthread.php?t=16994).)

We know. We've marked your card :D
rofl Well I'm an open minded guy. Explain to me it's merits over a standard language?

stanl
01-31-2008, 02:08 PM
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.

Oorang
01-31-2008, 02:53 PM
>> Not dissing AutoIT, just discussing :hide: <<

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 (http://jobsearch.monster.com/Search.aspx?re=130&cy=us&brd=1&JSNONREG=1&q=AutoIT&rad=20&rad_units=miles).) 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)?

stanl
02-01-2008, 04:46 AM
>> Not dissing AutoIT, just discussing :hide: <<


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.


;Winbatch 2007C - Using IMAPI2 to Test CD/DVD Media
;[ http://www.microsoft.com/downloads/details.aspx?FamilyId=B5F726F1-4ACE-455D-BAD7-ABC4DD2F147B&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
;/////////////////////////////////////////////////////////////////////////////////////////////////////