1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Au3 Screen Capture Script

Discussion in 'Programming' started by Cleptography, Sep 6, 2010.

  1. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83

Share This Page