Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/articles/programming/)
-   -   Au3 Screen Capture Script (http://www.go4expert.com/articles/au3-screen-capture-script-t23212/)

Cleptography 6Sep2010 06:39

Au3 Screen Capture Script
 
This one here is an autoit script that captures screen shots, compresses with current date and time, and adds values to the registry of windows to run at start up. Any questions just ask I am more than happy to answer any.

Au3 Screen Capture Script
-------------------------------
Code:

#NoTrayIcon

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <File.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#cs############
#            #
#  Variables  #
#            #
#ce############
;~Set Vars
;-----------Directories
$MainDir = @ScriptDir&"\ScreenShots"
$ArchDir = "\Archives"
$CapsDir = "\Captures"
$ScrnApp = @ScriptDir&"\ScreenShots.exe"

;-----------Registry Values
$RegRead = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScreenCapture")
$RegWrite = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", "ScreenCapture", "REG_SZ", $ScrnApp)

;-----------Time Stamp
$TimeStamp = "\"&@mon&@mday&@year&@hour&@min&@sec

;-----------Capture Loop Value
$CapLoop = 0

;-----------Zip File
$ZipFile = $MainDir&$ArchDir&$TimeStamp& '.zip'

;-----------Zip Source
$SourceFolder = $MainDir&$CapsDir
;~End Vars

;Check The Directories if Not Exist Create Them
If FileExists($MainDir) Then
Else

        DirCreate($MainDir&$ArchDir)
        DirCreate($MainDir&$CapsDir)
       
EndIf

;Check The Reg Value If Not Exist Write It
If $RegRead = -1 Then $RegWrite

#cs#################
#                  #
#  Capture Screen  #
#                  #
#ce#################
Do

        $Jpeg  = _ScreenCapture_Capture($MainDir&$CapsDir&$TimeStamp& '.jpg')
        Sleep(30000)
        $CapLoop = $CapLoop + 1
       
Until $CapLoop = 1

#cs#############
#              #
#  Zip Folder  #
#              #
#ce#############
;Zip Directory
Add_Folder_2_ZIP($SourceFolder, $ZipFile)
Exit

Func Add_Folder_2_ZIP($folder, $zip_filename, $flag = 4)
    Local $hZIP, $ZIP_fileheader, $obj_ZIP, $obj_Folder, $obj_Copy
    Local $obj_FolderCount, $obj_ZIPCount , $file

    $hZIP = FileOpen($zip_filename, 26)
    $ZIP_fileheader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
    FileWrite($hZIP, $ZIP_fileheader)
    FileClose($hZIP)

    $obj_ZIP = ObjCreate("Shell.Application")
    $obj_Folder = $obj_ZIP.NameSpace($folder)
    $obj_ZIP_Folder = $obj_ZIP.NameSpace($zip_filename)
    $obj_Copy = $obj_ZIP.NameSpace($zip_filename).CopyHere($obj_Folder.Items, $flag)
    Sleep(250)

    While 1
        $file = _FileInUse($zip_filename)
        If $file = -1 Then
            SetError(1, 0, 0)
            ExitLoop
        EndIf
        ConsoleWrite($file & @CRLF)
        Sleep(500)
        If $file = 0 Then ExitLoop
    WEnd
EndFunc

Func _FileInUse($sFilename, $iAccess = 0)
    Local $aRet, $hFile, $iError, $iDA
    Local Const $GENERIC_WRITE = 0x40000000
    Local Const $GENERIC_READ = 0x80000000
    Local Const $FILE_ATTRIBUTE_NORMAL = 0x80
    Local Const $OPEN_EXISTING = 3
    $iDA = $GENERIC_READ
    If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE)
    $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _
            "str", $sFilename, _
            "dword", $iDA, _
            "dword", 0x00000000, _
            "dword", 0x00000000, _
            "dword", $OPEN_EXISTING, _
            "dword", $FILE_ATTRIBUTE_NORMAL, _
            "hwnd", 0)
    $iError = @error
    If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1)
    $hFile = $aRet[0]
    If $hFile = -1 Then
        $aRet = DllCall("Kernel32.dll", "int", "GetLastError")
        If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1)
        Return SetError($aRet[0], 0, 1)
    Else
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
        Return SetError(@error, 0, 0)
    EndIf
EndFunc


shabbir 4Oct2010 10:22

Re: Au3 Screen Capture Script
 
If you liked this article do nominate this article for Article of the month - Sep 2010 Before 15th of October 2010.


All times are GMT +5.5. The time now is 05:28.