Sign in to follow this  
Followers 0
BigDaddyO

Print Screen For Errors

2 posts in this topic

I am writing an error log and that works great, It will also skip to the next program on the list "Excel" if Word has any errors in it. What I would like to do is along with the error writing, I want to capture a print screen of what ever is showing when the script fails, then paste that into the log file. Now, from what I understand i have to use a .rtf or .doc for pictures. Can I use the RecLog to paste a print screen, or is there another simple way to do this. This is the code I have so far. Note: there will be about 25 - 30 programs to test when this script is done.

Also, is there a way to close all open windows before starting on the next program to test?

Thanks,

Mike

AutoItSetOption ( "WinTitleMatchMode",2)

DirCreate("C:\Matrix")

$FILE="c:\Matrix\Matrix.log"
FileDelete( $FILE)

; =====================================
;Log File Creator
Func RecLog($DEBUGTEXT)
  FileWriteLine($FILE, $DEBUGTEXT)
EndFunc ;==>RecLog

$DebugText=("Script Start      " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DEBUGTEXT)

;======================================

;  BEGIN TESTING MS-WORD
$MSG =("Error with MS-Word")
Run("C:\Program Files\Microsoft Office\Office10\winword.exe")
If WinWaitActive("666Document", "", 10)Then 
  Send("Testing Script for Microsoft Word XP...^s")
  WinMenuSelectItem("Document","", "&File", "Save &As...")
  Else
;========Print screen for Error===========
    Send("!{PrintScreen}")
    Send("#r")
    Send("wordpad{ENTER}")
    WinWaitActive("Document")
    Send("^V")
    sleep(1000)
    send("^s")
    send("{delete}c:\Matrix\")
    Send($MSG)
    send("{ENTER}")
    Send("!{F4}")
    sleep(5000)

  If WinWaitActive("Save As", "", 10) Then 
     Send("{DELETE}")
     Send("c:\Testing.doc!S")
     If WinWaitActive("Testing.doc", "", 10) Then 
        WinClose("Testing.doc")
    sleep(1000)
        Send("{Lwin}R")
        If WinWaitActive("Run", "", 10) Then 
           Send("{DELETE}c:\Testing.doc{ENTER}")
           If WinWaitActive("Testing.doc", "", 10) Then 
              WinClose("Testing.doc")
              FileRecycle("c:\Testing.doc")
              $msg=("MS-WORD Test Passed:    " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
      RecLog($MSG)
     EndIf
        EndIf
     EndIf
  EndIf
EndIf

sleep(2000)

;BEGIN TESTING MS-EXCEL
$MSG=("Error with MS-Excel")
run("C:\Program Files\Microsoft Office\Office10\excel.exe")
if winwaitactive ("Microsoft Excel", "", 10)Then
    Send ("Testing Excel^s")
    if winwaitactive ("Save As", "", 10) Then
  send ("{DELETE}")
  send ("c:\Testing.xls!S")
  if winwaitactive ("Microsoft Excel", "", 10)Then
     WinClose ("Microsoft Excel - Testing.xls")
     send ("{Lwin}R")
     if winwaitactive ("Run", "", 10)Then
    send ("{DELETE}c:\Testing.xls{ENTER}")
    if winwaitactive ("Microsoft Excel - Testing.xls", "", 10)Then
     WinClose ("Microsoft Excel - Testing.xls")
     FileRecycle ("c:\testing.xls")
     $msg=("MS-EXCEL Test Passed:      " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
     RecLog($MSG)
    Endif   
     Endif
  Endif
    Endif
Endif

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I use a program called Thumbs+ that has a little setup to capture screens to file with a hotkey. I am sure there are a bunch of free ones that you could compile into your AutoIt file. They would copy the picture to a JPEG or GIF, and you could just look for the new file and place the link into the file.

If you wanted to do it the way you are saying, I would suggest opening wordpad or a program that can keep pictures in it, and having autoit fill in the information that way. Say:

run("C:\Program Files\Windows NT\Accessories\wordpad.exe",'',@SW_MINIMIZE)
winwait("Document - WordPad")
controlsend("Document - WordPad","","RichEdit20W1","Log file "& @mon&"/"&@mday&@crlf)
send("{PRINTSCREEN}")
sleep("1000")
winsetstate("Document - WordPad","",@SW_RESTORE)
controlsend("Document - WordPad","","RichEdit20W1","^v")
winsetstate("Document - WordPad","",@SW_MINIMIZE)
controlsend("Document - WordPad","","RichEdit20W1","{down}{enter}")
controlsend("Document - WordPad","","RichEdit20W1","Log file 2 "& @mon&"/"&@mday&@crlf)

It seems that you can't have the window Minimised and paste in the picture, not sure why though. As you can see, I placed a screenshot of the screen in the file, with some text. This should get you started, or give you an option.

edit...

well hide works well, here is an example of it working in the backround.

run("C:\Program Files\Windows NT\Accessories\wordpad.exe",'',@SW_HIDE)
winwait("Document - WordPad")
controlsend("Document - WordPad","","RichEdit20W1","Log file "& @mon&"/"&@mday&@crlf)
send("{PRINTSCREEN}")
sleep("1000")
controlsend("Document - WordPad","","RichEdit20W1","^v")
controlsend("Document - WordPad","","RichEdit20W1","{down}{enter}")
controlsend("Document - WordPad","","RichEdit20W1","Log file 2 "& @mon&"/"&@mday&@crlf)
winsetstate("Document - WordPad","",@SW_SHOW)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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