FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home » Windows » Windows Batch Script saves Screenshots every 10min

Windows Batch Script saves Screenshots every 10min

by Charles Torvalds

Due to overwhelming popular demand (you know who you are) I will share how I have a simple windows batch file that takes a screenshot of my desktop every 10 minutes, 24/7. This will be a real treat for me because I will be done here is only a couple minutes! (So probably an even bigger treat for many of you!). Before we get started (and finished). let me say that I have used this without any problems for over 2 years now. Don't believe anything can work that long on Windows? Ok let me get proof. Got it..

Back from 2010

Schedule Command

Originally I had this completely being handled in the BG without windows, but this is a much better way to do it. All that you need is to download the extermely powerful program free nircmd. Then go create a task in windows Scheduled Tasks wizard that saves a screenshot every 10 minutes or so, saving the file with the date in it. I set it to run on logon, and then most importantly, to only run while logged on to avoid hours of blank screens

C:\CRYPT\BIN\nircmd.exe loop 10 300000 savescreenshot "Z:\SS\~$currdate.MM-yyyy$\~$currdate.MM-dd-yy$-~$currtime.HHmm$.png"

Windows Batch Script saves Screenshots every 10min

Removing Dupes

Believe it or not, the screenshots are all setup now. And as you can see from this screenshot, they are very high -resolution. And even more useful to me is that nircmd takes a screenshot of ALL of your screen real-estate. Which as the screenshot above shows, I have 2 huge Dells side-byside, so this is just all good.

A Windows Batch Fiile

Yay I get to show off my mad windows batch-file skills... ya right. This batch file is actually prettty spectacular, it uses the imagemagick binaries to compare the digital image of the files next to it. After a little trial and error, it works perfect for me. A couple of tweaks fixed the problem of my taskbar clock updating clock skeing the reesults.

OptiPng

I almost forgot that this script also uses the optipng binary to reduce the size of all the images in the directory.

Contig

And it also uses the contig binary to selectively defragment the directo trees.

Turnkey

Once you get the duplicate script setup for your screens, you can schedule that to run once a week or so.

Auto-Remove Duplicates

Ok now this is the only reason I really agreeed to putting an article like this one up, it just so happens that I completed this script yesterday and it now deletes duplicates.

@ECHO OFF&& SETLOCAL&& PUSHD "%~dp0"&& SETLOCAL ENABLEDELAYEDEXPANSION&& SETLOCAL ENABLEEXTENSIONS&& SET V=5&& IF NOT "!V!"=="5" (ECHO DelayedExpansion Failed&& GOTO :EOF)

SET P1=^^^>^^^>^^^>
SET P2=++
SET P3=::
SET L1=+==============================================================================================================+
SET L2=+--------------------------------------------------------------------------------------------------------------+

SET RUNYEAR=2010
SET LISTBUFFER=0
SET SSDIR=Z:\SS\2010
SET SSLOG=ss.log
SET CCLOG=cc.log
SET LIKENESS=0

CALL :MM "Starting SS Optimization on %SSDIR% AT %DATE% %TIME%"
C:\CRYPT\BIN\du.exe -q %SSDIR% > %SSLOG%
TYPE %SSLOG% && SLEEP 2

CALL :MM "Removing Duplicates for %RUNYEAR% from %SSDIR%"
FOR %%i in (01 02 03 04 05 06 07 08 09 10 11 12) DO CALL :DUPEPASS "%SSDIR%\%%i-%RUNYEAR%"

CALL :MM "Optimizing %SSDIR% with optipng"
FOR /R %SSDIR% %%I in ( *.png ) DO CALL :OPTIPNGRUN %%I

CALL :MM "BEFORE SS PNG Optimization: %DATE% %TIME%"
TYPE %SSLOG% && SLEEP 2

CALL :MM "AFTER SS PNG Optimization: %DATE% %TIME%"
C:\CRYPT\BIN\du.exe -q %SSDIR%

CALL :MM "Defragmenting %SSDIR%"
C:\crypt\bin\Contig.exe -s %SSDIR% | FIND "files"  | FIND "d"

DEL /F /Q %SSLOG% %CCLOG%

POPD && ENDLOCAL && GOTO :EOF

:DUPEPASS
@ECHO DUPEPASS %~1
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
FOR /R %~1 %%i in ( *.png ) DO CALL :AREDUPLICATES %%i
EXIT /B

:AREDUPLICATES
IF %LISTBUFFER% NEQ 0 (
  ECHO > %CCLOG% 
  ECHO .....COMPARE %~1 %LISTBUFFER%
  "C:\Program Files\ImageMagick-6.6.4-Q16\compare.exe" -extract 3840x1100+10+10 -metric MAE %~1 %LISTBUFFER% NUL 2>%CCLOG%
  FOR /F "tokens=1 delims= " %%i in (%CCLOG%) DO SET LIKENESS=%%i
  SET /A LIKENESS*=1

  IF !LIKENESS! LSS 75 ECHO.&& ECHO ^>^>^> [!LIKENESS!] DELETING %LISTBUFFER% && DEL /F /Q %LISTBUFFER%
  SET LISTBUFFER=0
  
) ELSE (
  SET LISTBUFFER=%~1
)
EXIT /B

:OPTIPNGRUN
TITLE ^>^>^> PROCESSING %~1
C:\CRYPT\BIN\optipng.exe -zc 9 -zm 8 -zs 0 -f 0 -preserve "%~1" | FIND ", 1 color in palette" 1>NUL && ECHO ^>^>^> DELETING %~1 && @DEL /P /F /Q "%~1"
EXIT /B

:MM
ECHO. && ECHO %L1% && TITLE +++ %~1... && ECHO %P1% %~1... && ECHO %L2% && ECHO. && EXIT /B

:: nircmd.exe savescreenshotfull "Z:\SS\~$currdate.MM-dd-yy$-~$currtime.HHmm$.png"
:: sleep 2
:: compare -fuzz 10 -metric PSNR "%~1" "%~2" null:

:: if errorlevel 1 echo "Found It!" 

:: endlocal && exit /B
:: FOR /R Z:\SS\08-2010 %I in ( *.png ) DO @optipng -zc 9 -zm 9 -zs 0 -f 0 -preserve -simulate %I | FIND "1 color in palette" 1>nul && @ECHO DEL /F /Q %I
:: C:\WINDOWS\nircmd.exe savescreenshotfull "Z:\SS\~$currdate.MM-dd-yy$-~$currtime.HHmm$.png"

:: FOR /R Z:\SS\08-2010 %i in ( *.png ) DO @ECHO %i
:: FOR /R Z:\SS\06-2010 %i in ( 06-08-10*.png ) DO @ECHO %i
::GETLIST
::SET F=%~1
::SET F=%F:~0,19%
::FOR /R Z:\SS\06-2010 %%i in ( %F%*.png ) DO @ECHO %%i
::FOR /R Z:\SS\06-2010 %%i in ( *.png ) DO CALL :GETLIST %%i
::FOR /L %%i in (0,1,31) DO @SET M=00%%i && ECHO !M:~-3!

Download Duplication Batch Script

The duplication / defragmenting / Magical Batch File

Tags

Comments Welcome

Information is freedom. Freedom is non-negotiable. So please feel free to modify, copy, republish, sell, or use anything on this site in any way at any time ;)

My Online Tools

Popular Articles
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two.
-- Richard M. Stallman


It's very simple - you read the protocol and write the code. -Bill Joy

>

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

+Askapache | htaccess file | htaccess.guru

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service | @Htaccess

↑ TOPMain