Sign in to follow this  
Followers 0
S3rG

WIA Automation

4 posts in this topic

#1 ·  Posted (edited)

I wrote a small script to take files from DigiCam using WIA Automation.

But there is a small problem, how can i get time stamps or file creation time/date for a non image files, im looked for a solution, but didn't found any.

For an image file I can use an ImageFile "DateTime" property.

Thanks Creator for insperation.

#include-once

Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)
Opt("RunErrorsFatal", 0)


#region - WIA Constants
; FormatID

Global Const $wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatGIF = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatAVI = "{32F8CA14-087C-4908-B7C4-6757FE7E90AB}"

; EventID

Global Const $wiaEventDeviceConnected = "{A28BBADE-64B6-11D2-A231-00C04FA31809}"
Global Const $wiaEventDeviceDisconnected = "{143E4E83-6497-11D2-A231-00C04FA31809}"
Global Const $wiaEventItemCreated = "{4C8F4EF5-E14F-11D2-B326-00C04F68CE61}"
Global Const $wiaEventItemDeleted = "{1D22A559-E14F-11D2-B326-00C04F68CE61}"
Global Const $wiaEventScanImage = "{A6C5A715-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanPrintImage = "{B441F425-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanFaxImage = "{C00EB793-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanOCRImage = "{9D095B89-37D6-4877-AFED-62A297DC6DBE}"
Global Const $wiaEventScanEmailImage = "{C686DCEE-54F2-419E-9A27-2FC7F2E98F9E}"
Global Const $wiaEventScanFilmImage = "{9B2B662C-6185-438C-B68B-E39EE25E71CB}"
Global Const $wiaEventScanImage2 = "{FC4767C1-C8B3-48A2-9CFA-2E90CB3D3590}"
Global Const $wiaEventScanImage3 = "{154E27BE-B617-4653-ACC5-0FD7BD4C65CE}"
Global Const $wiaEventScanImage4 = "{A65B704A-7F3C-4447-A75D-8A26DFCA1FDF}"

; CommandID

Global Const $wiaCommandSynchronize = "{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandTakePicture = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandDeleteAllItems = "{E208C170-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandChangeDocument = "{04E725B0-ACAE-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandUnloadDocument = "{1F3B3D8E-ACAE-11D2-A093-00C04F72DC3C}"

; WiaSubType enumeration

Global Const $UnspecifiedSubType = 0
Global Const $RangeSubType = 1
Global Const $ListSubType = 2
Global Const $FlagSubType = 3

; WiaDeviceType enumeration

Global Const $UnspecifiedDeviceType = 0
Global Const $ScannerDeviceType = 1
Global Const $CameraDeviceType = 2
Global Const $VideoDeviceType = 3

; WiaItemFlag enumeration

Global Const $FreeItemFlag = 0x0
Global Const $ImageItemFlag = 0x01
Global Const $FileItemFlag = 0x02
Global Const $FolderItemFlag = 0x04
Global Const $RootItemFlag = 0x08
Global Const $AnalyzeItemFlag = 0x010
Global Const $AudioItemFlag = 0x020
Global Const $DeviceItemFlag = 0x040
Global Const $DeletedItemFlag = 0x080
Global Const $DisconnectedItemFlag = 0x0100
Global Const $HPanoramaItemFlag = 0x0200
Global Const $VPanoramaItemFlag = 0x0400
Global Const $BurstItemFlag = 0x0800
Global Const $StorageItemFlag = 0x01000
Global Const $TransferItemFlag = 0x02000
Global Const $GeneratedItemFlag = 0x04000
Global Const $HasAttachmentsItemFlag = 0x08000
Global Const $VideoItemFlag = 0x010000
Global Const $RemovedItemFlag = 0x80000000

; WiaPropertyType enumeration

Global Const $UnsupportedPropertyType = 0
Global Const $BooleanPropertyType = 1
Global Const $BytePropertyType = 2
Global Const $IntegerPropertyType = 3
Global Const $UnsignedIntegerPropertyType = 4
Global Const $LongPropertyType = 5
Global Const $UnsignedLongPropertyType = 6
Global Const $ErrorCodePropertyType = 7
Global Const $LargeIntegerPropertyType = 8
Global Const $UnsignedLargeIntegerPropertyType = 9
Global Const $SinglePropertyType = 10
Global Const $DoublePropertyType = 11
Global Const $CurrencyPropertyType = 12
Global Const $DatePropertyType = 13
Global Const $FileTimePropertyType = 14
Global Const $ClassIDPropertyType = 15
Global Const $StringPropertyType = 16
Global Const $ObjectPropertyType = 17
Global Const $HandlePropertyType = 18
Global Const $VariantPropertyType = 19
Global Const $VectorOfBooleansPropertyType = 101
Global Const $VectorOfBytesPropertyType = 102
Global Const $VectorOfIntegersPropertyType = 103
Global Const $VectorOfUnsignedIntegersPropertyType = 104
Global Const $VectorOfLongsPropertyType = 105
Global Const $VectorOfUnsignedLongsPropertyType = 106
Global Const $VectorOfErrorCodesPropertyType = 107
Global Const $VectorOfLargeIntegersPropertyType = 108
Global Const $VectorOfUnsignedLargeIntegersPropertyType = 109
Global Const $VectorOfSinglesPropertyType = 110
Global Const $VectorOfDoublesPropertyType = 111
Global Const $VectorOfCurrenciesPropertyType = 112
Global Const $VectorOfDatesPropertyType = 113
Global Const $VectorOfFileTimesPropertyType = 114
Global Const $VectorOfClassIDsPropertyType = 115
Global Const $VectorOfStringsPropertyType = 116
Global Const $VectorOfVariantsPropertyType = 119

; WiaImagePropertyType enumeration

Global Const $UndefinedImagePropertyType = 1000
Global Const $ByteImagePropertyType = 1001
Global Const $StringImagePropertyType = 1002
Global Const $UnsignedIntegerImagePropertyType = 1003
Global Const $LongImagePropertyType = 1004
Global Const $UnsignedLongImagePropertyType = 1005
Global Const $RationalImagePropertyType = 1006
Global Const $UnsignedRationalImagePropertyType = 1007
Global Const $VectorOfUndefinedImagePropertyType = 1100
Global Const $VectorOfBytesImagePropertyType = 1101
Global Const $VectorOfUnsignedIntegersImagePropertyType = 1102
Global Const $VectorOfLongsImagePropertyType = 1103
Global Const $VectorOfUnsignedLongsImagePropertyType = 1104
Global Const $VectorOfRationalsImagePropertyType = 1105
Global Const $VectorOfUnsignedRationalsImagePropertyType = 1106

; WiaEventFlag enumeration

Global Const $NotificationEvent = 1
Global Const $ActionEvent = 2

; WiaImageIntent enumeration

Global Const $UnspecifiedIntent = 0
Global Const $ColorIntent = 1
Global Const $GrayscaleIntent = 2
Global Const $TextIntent = 4

; WiaImageBias enumeration

Global Const $MinimizeSize = 65536
Global Const $MaximizeQuality = 131072

#endregion
;

Local $DevID = ""
Local $Dev

Local $Itm

Local $Img

Local $property

Local $command

Local $COMerror = ObjEvent("AutoIt.Error","MyErrFunc")

Local $wiaDev = ObjCreate("WIA.DeviceManager");not used yet
Local $wiaDlg = ObjCreate("WIA.CommonDialog")

$Dev = $wiaDlg.ShowSelectDevice($CameraDeviceType)

For $Itm In $Dev.Items
    
    If BitAND($Itm.Properties("Item Flags").Value, $FolderItemFlag) Then ContinueLoop
    
    $Img = $wiaDlg.ShowTransfer($Itm)
    If Not IsObj($Img) Then 
        ContinueLoop
    EndIf
    
    Switch $Itm.Properties("Format").Value
        Case $wiaFormatJPEG
    EndSwitch

    $Img.SaveFile(@ScriptDir & "\" & $Itm.Properties("Item Name").Value & "." & StringLower($Itm.Properties("Filename extension").Value))

Next

Func MyErrFunc()
  Local $HexNumber=hex($COMerror.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $COMerror.description  & @CRLF & _
             "err.windescription:"   & @TAB & $COMerror.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $COMerror.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $COMerror.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $COMerror.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $COMerror.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $COMerror.helpcontext _
            )
  SetError(1) 
Endfunc
Edited by S3rG

Share this post


Link to post
Share on other sites



I wrote a small script to take files from DigiCam using WIA Automation.

But there is a small problem, how can i get time stamps or file creation time/date for a non image files, im looked for a solution, but didn't found any.

FileGetTime() and FileGetVersion().

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

FileGetTime() and FileGetVersion().

It works only for image files like jpeg because they have an exif information.

FileGetTime() doesn't work for any kind of files, because the files get the file creation time on a harddrive ( $Img.SaveFile )

and it's even not the time of image, video or CRW (Canon RAW) shooting.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@all

I am not sure if this can help you ?

#include <string.au3>

$message = "Select a file that has Metadata properties set"

$filename = FileOpenDialog($message, @DesktopDir & "\", "All (*.*)", 1)

If @error Then
    MsgBox(4096,"","No File(s) chosen")
    Exit
EndIf

; ADS file containing most extended properties
$ads1 = $filename&":"&Chr(5)&"SummaryInformation" 

; ADS file containing the category information
$ads2 = $filename&":"&Chr(5)&"DocumentsummaryInformation"


If Not FileExists($ads1) Then
    MsgBox(16,"Error","The file: " & @CRLF & "   " & $filename & @CRLF & "does not have any metadata properties set. "&@CRLF & @CRLF&"Please choose a different file")
    Exit
EndIf

$propType_1 = 2
$propType_2 = 30
$propType_3 = 30
$propType_4 = 30
$propType_5 = 30
$propType_6 = 30
$propType_7 = 30
$propType_8 = 30
$propType_9 = 30
$propType_10 = 64
$propType_11 = 64
$propType_12 = 64
$propType_13 = 64
$propType_14 = 3
$propType_15 = 3
$propType_16 = 3
$propType_17 = 71
$propType_18 = 30
$propType_19 = 3

$propDesc_1 = "Code page"
$propDesc_2 = "Title"
$propDesc_3 = "Subject"
$propDesc_4 = "Author"
$propDesc_5 = "Keywords"
$propDesc_6 = "Comments"
$propDesc_7 = "Template"
$propDesc_8 = "Last Saved By"
$propDesc_9 = "Revision Number"
$propDesc_10 = "Total Editing Time"
$propDesc_11 = "Last Printed"
$propDesc_12 = "Create Time/Date"
$propDesc_13 = "Last Saved Time/Date"
$propDesc_14 = "Number of Pages"
$propDesc_15 = "Number of Words"
$propDesc_16 = "Number of Characters"
$propDesc_17 = "Thumbnail"
$propDesc_18 = "Name of Creating Application"
$propDesc_19 = "Security"






;16 = Force binary(byte) reading and writing mode with FileRead and FileWrite
;32 = Use Unicode UTF16 Little Endian mode when writing text with FileWrite and FileWriteLine (default is ANSI)
$word = 2
$dword = 4
$byte = 1
$guid = $dword + ($word * 2) + ($byte * 2) + ($byte * 6)

$file = FileOpen($ads1, 16+32)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
Global $data = Hex(FileRead($file))
FileClose($file)

; read header

$byteOrderMarkForUTF16LE = Chomp(0x00,$word)
ConsoleWrite("$byteOrderMarkForUTF16LE: " & $byteOrderMarkForUTF16LE & @CRLF)

$streamValidation = Chomp(0x02,$word)
ConsoleWrite("$streamValidation: " & $streamValidation & @CRLF)

$unknownPurpose = Chomp(0x04,$word)
ConsoleWrite("$unknownPurpose: " & $unknownPurpose & @CRLF)

$OSIndicator = Number(LEDec(Chomp(0x06,$word)))
ConsoleWrite("$OSIndicator: " & $OSIndicator & @CRLF)

$streamClassID = Chomp(0x08,$guid )
ConsoleWrite("$streamClassID: " & $streamClassID & @CRLF)

$sectionCount = Dec(LEDec(Chomp(0x18,$dword)))
ConsoleWrite("$sectionCount: " & $sectionCount & @CRLF)


; read section declarations

$sect1ClassID = LEDec(Chomp(0x1c,$guid)) ; not sure this should be LE decoded
ConsoleWrite("$sect1ClassID: " & $sect1ClassID & @CRLF)

$sect1Offset = Dec(LEDec(Chomp(0x2c,$dword)))
ConsoleWrite("$sect1Offset: " & $sect1Offset & @CRLF)

; read first section header

$sect1Length = Dec(LEDec(Chomp($sect1Offset+0x00,$dword)))
ConsoleWrite("$sect1Length: " & $sect1Length & @CRLF)

$sect1PropCount = Dec(LEDec(Chomp($sect1Offset+0x04,$dword)))
ConsoleWrite("$sect1PropCount: " & $sect1PropCount & @CRLF)

; read Property declarations

$cursor = 0x04
For $i = 1 To $sect1PropCount
    
    ConsoleWrite("------------------" & @crlf)
    
    ; read property ID and Offset from Section Header
    
    $cursor += $dword
    $PropId = Dec(LEDec(Chomp($sect1Offset+$cursor,$dword)))
    $cursor += $dword
    $PropOffset = Dec(LEDec(Chomp($sect1Offset+$cursor,$dword)))
    $realPropOffset = $sect1Offset+$PropOffset
    $propType = PropGetType($propID)
    
    
    $propDesc = PropGetDesc($propID)
    
    Switch $propType
        Case 2  
            ConsoleWrite("2 byte signed integer" & @CRLF)
        Case 3  
            ConsoleWrite("4 byte signed integer" & @CRLF)
        Case 30 
            ConsoleWrite("null-terminated string prepended by dword string length" & @CRLF)
        Case 64 
            ConsoleWrite("Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601)" & @CRLF)
        Case 71 
            ConsoleWrite("Clipboard format" & @CRLF)
        Case Else
            ConsoleWrite("Unknown Type" & @CRLF)
    EndSwitch

    ConsoleWrite($i & " $PropId: " & $PropId & @CRLF)
    ConsoleWrite($i & " $realPropOffset: " & $realPropOffset & @CRLF)
    ConsoleWrite($i & " $propType: " & $propType & @CRLF)
    
    
    $ptype = Dec(LEDec(Chomp($realPropOffset,$dword))) ; always 31? WTF?
    ConsoleWrite("$ptype = " & $ptype & @CRLF)
    $plen = Dec(LEDec(Chomp($realPropOffset+$dword,$dword)))
    ConsoleWrite("$plen = " & $plen & @CRLF)
    
    $pdataLoc = $realPropOffset+$dword+$dword
    $pcursor = 0 
    $propStringValue = ""
    While 1
        $char = Dec(LEDec(Chomp($pdataLoc+$pcursor,$word)))
        If $char = "0000" Then ExitLoop
        $propStringValue &= Chr($char)
        $pcursor += $word
    WEnd
    ConsoleWrite("! " & $propDesc & ": " &$propStringValue & @CRLF)
    
Next




;read a number of hex characters from a given offset point
Func Chomp($offset,$length)
    ;ConsoleWrite($offset & ": ")
    $charPosition = ($offset*2)+1
    $charLen = $length*2
    Return StringMid($data,$charPosition,$charLen)
EndFunc

; little endian decoder
Func LEDec($hexstring)
    Local $output = ""
    For $i = 1 To StringLen($hexstring) Step 2
        $output = StringMid($hexstring,$i,2) & $output
    Next
    Return $output
EndFunc



Func PropGetType($propID)
    If IsDeclared ("propType_"&$propID) Then
        Return Eval("propType_"&$propID)
    Else
        Return ""
    EndIf
EndFunc

Func PropGetDesc($propID)
    If IsDeclared ("propDesc_"&$propID) Then
        Return Eval("propDesc_"&$propID)
    Else
        Return ""
    EndIf
EndFunc



Exit
ConsoleWrite("---------------------" & @CRLF)
$count = 0
While StringLen($data) > 0
    $char = StringLeft($data,2)
    $data = StringTrimLeft($data,2)
    $ascii = StringStripCR(_HexToString($char))
    ConsoleWrite($count & @TAB & $char & @TAB & $ascii & @CRLF)
    $count += 1
WEndoÝ÷ Øêæk&Þ¶¬jëh×6;===============================================================================
; EXIF Parser
;===============================================================================
Func ParseExif($hFile, $exif_offset)
    Local $ByteOrder = 0, $sInfo = ""
    Local $nEIFDOffset, $aTag[1][2]
    Local $sSpecialTags = "0112,8822,9208,9207,9209,9101,0128,A217,A403,A402,A406,A408,A409,A40A"

    _AddPair($aTag, 0x0100, "ExifWidth")
    _AddPair($aTag, 0x0101, "ExifHeight")
    _AddPair($aTag, 0x011A, "XResolution")
    _AddPair($aTag, 0x011B, "YResolution")
    _AddPair($aTag, 0x0102, "Colordepth")
    _AddPair($aTag, 0x0132, "DateTime")
    _AddPair($aTag, 0x9003, "DateTimeOriginal")
    _AddPair($aTag, 0x9004, "DateTimeDigitized")
    _AddPair($aTag, 0x9102, "CompressedBitsPerPixel")
    _AddPair($aTag, 0x9000, "ExifVersion")
    _AddPair($aTag, 0x9204, "ExposureBiasValue")
    _AddPair($aTag, 0x829A, "ExposureTime")
    _AddPair($aTag, 0x829D, "FNumber")
    _AddPair($aTag, 0x920A, "FocalLength")
    _AddPair($aTag, 0x8827, "ISO")
    _AddPair($aTag, 0x010F, "Make")
    _AddPair($aTag, 0x9202, "ApertureValue")
    _AddPair($aTag, 0x9205, "MaxApertureValue")
    _AddPair($aTag, 0x0110, "Model")
    _AddPair($aTag, 0x0131, "Software")
    _AddPair($aTag, 0x010E, "ImageDescription")
    _AddPair($aTag, 0x013B, "Artist")
    _AddPair($aTag, 0x8298, "Copyright")
    _AddPair($aTag, 0xA420, "ImageUniqueID")
    _AddPair($aTag, 0x9286, "UserComments")
    _AddPair($aTag, 0x9201, "ShutterSpeedValue")
    _AddPair($aTag, 0x9202, "ApertureValue")
    _AddPair($aTag, 0x9203, "BrightnessValue")
    _AddPair($aTag, 0x9206, "SubjectDistance")
    _AddPair($aTag, 0xA404, "DigitalZoomRatio")

    $nTiffHdrOffset = $exif_offset + 10 ; Start of TIFF header

    $pHdr = _FileReadToStruct("short;short;dword", $hFile, $nTiffHdrOffset)
    If DllStructGetData($pHdr, 1) = 0x4D4D then $ByteOrder = 1
    $nIFDOffset = _IntR(DllStructGetData($pHdr, 3), $ByteOrder)
    $pCnt = _FileReadToStruct("ushort", $hFile, $nTiffHdrOffset + $nIFDOffset) ; Tags count
    $nIFDCount = _IntR(DllStructGetData($pCnt, 1), $ByteOrder)

    $pTag = DllStructCreate("ushort;ushort;udword;udword")

    For $nCnt = 0 To $nIFDCount - 1
        $pTag = _FileReadToStruct($pTag, $hFile, $nTiffHdrOffset + $nIFDOffset + 2 + $nCnt * 12)
        $id = DllStructGetData($pTag, 1)
        $id = _IntR($id, $ByteOrder)
        For $i = 1 To $aTag[0][0]
            If $aTag[$i][0] = $id Then
                _Add($sInfo, $aTag[$i][1], _ReadTag($hFile, $pTag, $nTiffHdrOffset, $ByteOrder))
                Exitloop
            Endif
        Next
        If StringInStr($sSpecialTags, Hex($id, 4)) Then _AddSpecial($sInfo, $id, _ReadTag($hFile, $pTag, $nTiffHdrOffset, $ByteOrder))
        If $id = 0x8769 Then ; Exif IFD Offset
           $nEIFDOffset = _ReadTag($hFile, $pTag, $nTiffHdrOffset, $ByteOrder)
           $pCnt = _FileReadToStruct($pCnt, $hFile, $nTiffHdrOffset + $nEIFDOffset)
           $nEIFDCount = _IntR(DllStructGetData($pCnt, 1), $ByteOrder)
        Endif
    Next

    If not ($nEIFDOffset > 0) Then Return($sInfo)

    For $nCnt = 0 To $nEIFDCount - 1
        $pTag = _FileReadToStruct($pTag, $hFile, $nTiffHdrOffset + $nEIFDOffset + 2 + $nCnt * 12)
        $id = DllStructGetData($pTag, 1)
        $id = _IntR($id, $ByteOrder)
        For $i = 1 To $aTag[0][0]
            If $aTag[$i][0] = $id Then 
                _Add($sInfo, $aTag[$i][1], _ReadTag($hFile, $pTag, $nTiffHdrOffset, $ByteOrder))
                Exitloop
            Endif
        Next
        If StringInStr($sSpecialTags, Hex($id, 4)) Then _AddSpecial($sInfo, $id, _ReadTag($hFile, $pTag, $nTiffHdrOffset, $ByteOrder))
    Next
    $pHdr = 0
    $pCnt = 0
    $pTag = 0
    Return($sInfo)
EndFunc

regards

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0