Problems with ScreenCapture Loop

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
jcrens8392
Newbie
Posts: 1
Joined: Thu Jun 03, 2010 8:11 pm

Problems with ScreenCapture Loop

Post by jcrens8392 » Thu Jun 03, 2010 8:19 pm

Hi,

I'm evaluating MacroScheduler for purchase.

I have a loop in which I run the ScreenCapture command to save a screenshot to a particular file.

The filename does not change on each loop because there are several thousand iterations and I don't want to flood my hard drive with screenshot images.

Everything works perfectly on the first loop, but the second time around, I get an error # 2 from SCREENCAP_RESULT indicating the image could not be saved to the specified file.

I've done some testing and can only guess that this may be a result of that image not being released by whatever process is saving to it so that by the time the next ScreenCapture command is run, the image is still locked.

Is there any validity to this suspicion, and if so, is there a way to force the release of that file?

Incidentally, each loop takes roughly 2 minutes to complete, so I can't imagine it's just moving too fast for my OS.

Finally, I have tried saving the screenshots to separate files on each loop and it works fine, so there doesn't appear to be any syntax problems with my code.

Thanks in advance for any help!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu Jun 03, 2010 8:48 pm

This sample code works fine for me. I'm using MS ver 10.1.21 on XP service pack 3 inside a VMWare virtual machine.

[code]

Label>Loop
ScreenCapture>10,10,200,200,c:\mypic.bmp
If>SCREENCAP_RESULT>0
MessageModal>Error saving screencapture - %SCREENCAP_RESULT%
Endif
Wait>5
Goto>Loop

[/code]

I think we need to know more about your operating environment. Also can you post your code for us to look at?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jun 03, 2010 8:53 pm

The following loops 5 times and saves the captured screen to the same file name each time. This does not error for me....


I see adroege has just posted more or less the same thing. I'm using the latest version 12.1

Code: Select all

Let>kk=0

Label>Loop
  ScreenCapture>0,0,100,100,%temp_dir%screencapturefile.jpg
  Add>kk,1
  If>kk=5
    Exit>0
  EndIf
  Wait>2
Goto>Loop

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Fri Jun 04, 2010 2:27 pm

Finally, I have tried saving the screenshots to separate files on each loop and it works fine, so there doesn't appear to be any syntax problems with my code.
Check your permissions in the folder where you are writing files. If you do not have "Full Control" you will not be able to delete existing files, even ones you created. The ability to create files only requires "Modify" or "Write" permissions. Try deleting or overwriting files manually to check how this works. You should not have these problems if you write to your personal file folders such as "My Documents", "My Pictures", or the SCRIPT_DIR where you are developing your script.


If that is not the problem, notice the examples posted by adroege and JRL do ScreenCapture for only a small portion of the screen and include a small wait. This might make a difference if your script overtakes the machines caching capabilities (if that is possible). Also, JRL wrote a jpg file which is smaller.

Additions to original Post:

I noticed on my machine only local administrators can delete files on folders other than the users personal folders. A standard user will not be able to delete or overwrite files for example on on the root folder C:\.

I also ran this test with no problems:

Code: Select all

Let>xx=0
Repeat>xx
Let>xx=%xx%+1
ScreenCapture>0,0,1200,1000,%SCRIPT_DIR%\ScreenCaptureTest.bmp
Until>xx=100
Note the large image size, the larger bmp file type, and no waits. I would estimate it overwrote the file about 8 times a second.


Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts