Jump to content
Sign in to follow this  
romulous

Interesting Limitation in AutoIt

Recommended Posts

romulous

Hi,

I use an AutoIt script as part of my nightly backups. The script is simple - run a batch file I have created, wait for the Command Prompt window to display, and then send a "Space Key" to it. I have the backup scripts run overnight, and whenever I check the logs, I find that the AutoIt part of the script is failing - even though when I run the script manually and watch it, it always works perfectly. Anyway, after a bit of thought, I've worked out what the problem is (I've tested it to confirm). The PC that AutoIt runs on is XP Home, I'm using the latest AutoIt version, and the Windows screensaver is set to come on after 10 minutes of inactivity (with the 'on resume, password protect' option selected) - this bit is important. What happens is that overnight, the PC is not used - so the Windows screensaver is on. Then, when the AutoIt script runs, it cannot (while the screen is locked by the screensaver), see the Command Prompt window to send the keypress to it. What I did to confirm this was to set the task to run not at 8pm, but two minutes from now. I then pressed Ctrl+Alt+Del and clicked on the 'lock screen' button. I then left the PC alone for two minutes, and then unlocked it - and sure enough, the Command Prompt was sitting there (so AutoIt had run that part of it ok), but the keypress had not been sent. It could be important to know that the screensaver part had not come on - I had just locked the PC. I haven't tested it as yet, so I'm not sure if the script would still fail if the screensaver was on, but the 'on resume, password protect' option was not selected. Most definitely, AutoIt fails when the PC/screen is locked. Anyway, can anyone tell me if this is a known limitation in AutoIt, and if there are any workarounds apart from disabling the screensaver?

Thanks,

CM

Edited by romulous

Share this post


Link to post
Share on other sites
McGod

Hi,

I use an AutoIt script as part of my nightly backups. The script is simple - run a batch file I have created, wait for the Command Prompt window to display, and then send a "Space Key" to it. I have the backup scripts run overnight, and whenever I check the logs, I find that the AutoIt part of the script is failing - even though when I run the script manually and watch it, it always works perfectly. Anyway, after a bit of thought, I've worked out what the problem is (I've tested it to confirm). The PC that AutoIt runs on is XP Home, I'm using the latest AutoIt version, and the Windows screensaver is set to come on after 10 minutes of inactivity (with the 'on resume, password protect' option selected) - this bit is important. What happens is that overnight, the PC is not used - so the Windows screensaver is on. Then, when the AutoIt script runs, it cannot (while the screen is locked by the screensaver), see the Command Prompt window to send the keypress to it. What I did to confirm this was to set the task to run not at 8pm, but two minutes from now. I then pressed Ctrl+Alt+Del and clicked on the 'lock screen' button. I then left the PC alone for two minutes, and then unlocked it - and sure enough, the Command Prompt was sitting there (so AutoIt had run that part of it ok), but the keypress had not been sent. It could be important to know that the screensaver part had not come on - I had just locked the PC. I haven't tested it as yet, so I'm not sure if the script would still fail if the screensaver was on, but the 'on resume, password protect' option was not selected. Most definitely, AutoIt fails when the PC/screen is locked. Anyway, can anyone tell me if this is a known limitation in AutoIt, and if there are any workarounds apart from disabling the screensaver?

Thanks,

CM

Does your script use PixelSearch, GetColor or Checksum?

Share this post


Link to post
Share on other sites
romulous

Does your script use PixelSearch, GetColor or Checksum?

Hi Chip,

Nope, none of those. The full script is:

CODE
Run ( "c:\purge.bat" ) ; Runs the Purge batch file

Sleep ( 3000 ) ; Sleeps for 3 seconds to give the command window launched by purge.bat time to display

WinActivate ( "C:\WINDOWS\system32\cmd.exe" ) ; Makes the command window active just to be sure (it should already be though)

Send ( "{SPACE}" ) ; Sends a Space to the command windoe (i.e. the XXCOPY prompt)

Exit ; Exits

Regards,

CM

Share this post


Link to post
Share on other sites
poisonkiller

Try replacing Sleep(3000) with WinWait("C:\WINDOWS\system32\cmd.exe").

Share this post


Link to post
Share on other sites
Jos

The story sounds pretty logical to me and I fail to see the Autoit3 Limitation.

Can you enter anything into a CMD wondow with the screen saver activated ? so why would the be different from the AutoIt3 Send command ?

You could try to see if using StdWrite() to sent something to the CMD window ...

:)

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
/dev/null

The story sounds pretty logical to me and I fall to see the Autoit3 Limitation.

Can you enter anything into a CMD wondow with the screen saver activated ? so why would the be different from the AutoIt3 Send command ?

You could try to see if using StdWrite() to sent something to the CMD window ...

:)

Or better, use xcopy in batch mode, so you don't have to interact with it.


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
romulous

Well, it's not entirely logical to me - I can't see the command window, but AutoIt should be able to, and thus shouldn't have a problem entering a keypress. I'll report it in the bugs forum just to be sure. Anyway, I tried another test of the script, this time with the screensaver on, but the 'lock' option off - and the script works. Basically because as soon as Windows scheduler runs the script, the screensaver is disabled (like when you press a key the screensaver goes away). So, the script only fails when the screen is locked.

poisonkiller: I tried that change, and that breaks the script entirely. With that line, the script fails (doesn't send the keypress) even when the screen is not locked.

/dev/null: It's actually xxcopy (www.xxcopy.com) I'm using, and the reason why I need the keypress is that the version of xxcopy that I use was released before SP2 for XP was released. That means that xxcopy see's the XP SP2 PC as an 'untested OS', and thus it puts up a prompt whereby you need to press a key within 2 minutes or xxcopy closes without doing anything. If the prompt was to continue with the script unless you press a key within 2 minutes, I wouldn't have a problem, but the xxcopy programmer obviously thought it would be funny to make the command do nothing instead. Though the OS is 'untested' for this version of xxcopy, it works fine with it. I'm not upgrading to a later version of xxcopy that recognises SP2 because later versions of xxcopy continually prompt you to upgrade to the Pro version of xxcopy - and therefore I would still have prompts to deal with (I don't gain anything). These Pro prompts of later versions are actually very difficult to deal with automatically (I've tried) - they aren't just simple prompts, they are a slow, line by line ascii art of characters. I doubt AutoIt could handle that sort of thing (the only thing I have seen that can handle them is a PowerPro script). At least the 'untested' prompt is a simple line of text which AutoIt can handle. xxcopy is really a pain in the backside when it comes to unattended scripts, and I have phased it out for all the other parts of the backup (using Robocopy instead) - except one. The part of the backup that Robocopy still can't handle is the purge part. I only need to purge files over 10 days old - unfortunately, the /purge switch of Robocopy cannot be modified, including by any of the date switches (like /minage). Robocopy thus purges everything when you try to use it for this part. xxcopy is the only file copy utility I know of that can have its purge command modified to check for dates. If I ever find one that can handle a purge by date only, then xxcopy is gone from that PC - I shouldn't have to use AutoIt just to do a stupid, unattended backup.

Regards,

CM

Share this post


Link to post
Share on other sites
lokster

I think that Autoit fails to activate the window, because the screen is locked and is covered by the 'Workstation locked" prompt, which allways stays active. Can you activate a window while the workstation is locked?

To me, this is not a limitation of AutoIt. It's a "feature" of windows that is working exactly the way it is supposed to work.

Maybe you must try different approach to the problem.

Share this post


Link to post
Share on other sites
romulous

I think that Autoit fails to activate the window, because the screen is locked and is covered by the 'Workstation locked" prompt, which allways stays active. Can you activate a window while the workstation is locked?

To me, this is not a limitation of AutoIt. It's a "feature" of windows that is working exactly the way it is supposed to work.

Maybe you must try different approach to the problem.

Hi lokster,

That is a good thought, I hadn't thought of the problem being caused for that reason. And now thinking about it, I don't know if you can actually activate a window while a workstation is locked. Certainly not in a human way (i.e. you don't have a magic keypress that works in the background behind the locked screen, you have to unlock the screen first to use the Start Menu, open Notepad or whatever). I guess the important thing for AutoIt is: could you activate a window programatically while the PC is locked? I don't honestly know the answer to that. As you say, the lock function in Windows may have been designed to specifically stop this, and things may be working as intended. If that's the case, then nothing can be done with AutoIt, I really only have two choices that I can see (that different approach):

1. Disable the 'lock on resume' function in the screensaver (which I was using to keep the PC secure, to stop people from getting onto it and doing mischief - e.g. deleting the backups intentionally).

2. Find an alternative to xxcopy for the purge function of the backup (which is the only part left that still uses xxcopy).

Number 2 would be the better solution (no AutoIt script would be needed, and I could leave the 'lock on resume' enabled), but I just don't know of any other tool that can purge like that. I still think Microsoft made a wrong design decision when they made Robocopy ignore the /minage switch when the /purge switch is used. I only have version XP010 of Robocopy (the one that comes with the Server 2003 resource kit on the Microsoft website), and I have heard that version XP026 comes with Vista, but I don't hold much hope for that newer version being different in this respect (I don't have a copy of Vista to check anyway). Still, if anyone can think of a freeware tool that could replace xxcopy in this situation, please let me know. Basically all the xxcopy command I have setup does is to:

-check the source folder (i.e. the files being backed up)

-check the destination folder (i.e. where the files are copied to)

-deletes any files that are in the destination but not in the source any longer - as long as they are over 10 days old. If they are not, they are not purged (until they reach 10 days old obviously - the batch file runs once per day)

Regards,

CM

Edited by romulous

Share this post


Link to post
Share on other sites
lokster

Maybe if you run c:\purge.bat this way:

$pid = Run ( "c:\purge.bat","",@SW_SHOW, 1)oÝ÷ ÛX¬~ôߤBÃjwZ~׫jëh×6Sleep(3000)oÝ÷ ÙÚºÚ"µÍÝ[Ü]J    ÌÍÜY
it will work?

But I am not sure if StdinWrite works with .bat files.

Share this post


Link to post
Share on other sites
romulous

Maybe if you run c:\purge.bat this way:

$pid = Run ( "c:\purge.bat","",@SW_SHOW, 1)oÝ÷ ÛX¬~ôߤBÃjwZ~׫jëh×6Sleep(3000)ƒoÝŠ÷ ÙÚºÚ"µÍ”Ý[•Üš]J    ˆÌÍŽÜYŒ
it will work?

But I am not sure if StdinWrite works with .bat files.

Well, one way to find out :rolleyes: I will test your change out tomorrow and find out (and will report back here on how it went).

CM

Share this post


Link to post
Share on other sites
romulous

Well, one way to find out :rolleyes: I will test your change out tomorrow and find out (and will report back here on how it went).

CM

Ok, after trying this, I can confirm that it doesn't work. All that happens is that a blank (with no text) command window is displayed. Think I will have to find an alternate tool to xxcopy.

CM

Share this post


Link to post
Share on other sites
ResNullius

The full script is:

CODE
Run ( "c:\purge.bat" ) ; Runs the Purge batch file

Sleep ( 3000 ) ; Sleeps for 3 seconds to give the command window launched by purge.bat time to display

WinActivate ( "C:\WINDOWS\system32\cmd.exe" ) ; Makes the command window active just to be sure (it should already be though)

Send ( "{SPACE}" ) ; Sends a Space to the command windoe (i.e. the XXCOPY prompt)

Exit ; Exits

What is the requirement for sending the "space" to the command prompt? What does it accomplish? Also, can you give us an example of the commands contained in the "purge.bat" file? I'm sure there is some way to accomplish the same end result.

Share this post


Link to post
Share on other sites
PsaltyDS

Just for giggles, I did this demo.

Here is the batch file at C:\Temp\Test.bat:

@echo off
echo I will now pause and wait for you to hit a key...
pause
:Loop
echo You hit a key!  
time /t
echo Do it again...
pause
Goto :Loop

And here is the script to send it spaces:

Run("c:\temp\test.bat")
Sleep(3000)
$n = 0
While WinExists("C:\WINDOWS\system32\cmd.exe")
    WinActivate("C:\WINDOWS\system32\cmd.exe")
    Sleep(3000)
    Send("{SPACE}")
    $n += 1
WEnd
MsgBox(64, "Results", "Looped " & $n & " times." )

Works fine for me.

:rolleyes:

Edit: Tweaked to check what happens when screen saver activates. Exactly as expected, that pauses the AutoIt script on the Win* functions, and it continues right on when the screen saver is cleared.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
FreeFry

I think there's an very easy solution to this.

You can automate input prompts with the use of simple 'input' files.

For example a simple test with the pause command:

(save as .bat file)

@echo off
echo Normal pause:
pause
echo Automated pause:
pause < test.txt

and create a test.txt text file in the same directory as the batch script, containing a space, then run it.

First pause will be executed normally, and require human input,

second pause will get it's input from the text file, and thus, become automated.

The space was just an example(as the pause command accepts any key to be pressed), you can just replace it with the key you need to send. :rolleyes:

Good luck :rambo:

Edit:

Clarified.

Edited by FreeFry

Share this post


Link to post
Share on other sites
herewasplato

...pauses the AutoIt script on the Win* functions, and it continues right on when the screen saver is cleared.

WinWait and WinExists should work when locked - WinActivate will (and should) not work.

I've used Beep() to test WinWait while the system is locked and had no problems.

However, the purge function that the OP mentioned could be done via AutoIt instead of xxcopy. I wonder if someone has already coded/posted such a UDF?

-MSP-


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

...poisonkiller: I tried that change, and that breaks the script entirely. With that line, the script fails (doesn't send the keypress) even when the screen is not locked....

Then you have some other problem - cuz this works for most of us :-)
Run("cmd")
WinWait("C:\WINDOWS\system32\cmd.exe")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
romulous

What is the requirement for sending the "space" to the command prompt? What does it accomplish? Also, can you give us an example of the commands contained in the "purge.bat" file? I'm sure there is some way to accomplish the same end result.

Hi,

Space was just the key I chose at random, it could be any key on the keyboard really - the command prompt is actually asking for a keypress to continue running the batch file. The contents of purge.bat are:

c:

cd c:\Images

xxcopy C:\Temp_Backups\ /RS /E /H /DB#11 /oNc:\Temp_Backups\log.txt /PD0 /Y >c:\Temp_Backups\Purge.txt

cd c:\

Basically because xxcopy doesn't recognise XP SP2, it pops up a message when that command is ran, saying that it is running on an unsupported operating system, and that if you don't press a key within 2 minutes, the command will exit. It's a stupid error message - the deault should be to press a key within 2 minutes to stop the command running instead of having to press the key to get the command to run. It was when xxcopy started to pop up these messages (after I had installed SP2 on the PC), that I began looking for ways to send a keypress to the command prompt. I then started experimenting with an AutoIt script that runs the purge.bat file, sends a keypress to the command prompt window (to satisfy xxcopy) and then exits.

Regards,

CM

Share this post


Link to post
Share on other sites
RDSchaefer

Hi,

I use an AutoIt script as part of my nightly backups. The script is simple - run a batch file I have created, wait for the Command Prompt window to display, and then send a "Space Key" to it. I have the backup scripts run overnight, and whenever I check the logs, I find that the AutoIt part of the script is failing - even though when I run the script manually and watch it, it always works perfectly. Anyway, after a bit of thought, I've worked out what the problem is (I've tested it to confirm). The PC that AutoIt runs on is XP Home, I'm using the latest AutoIt version, and the Windows screensaver is set to come on after 10 minutes of inactivity (with the 'on resume, password protect' option selected) - this bit is important. What happens is that overnight, the PC is not used - so the Windows screensaver is on. Then, when the AutoIt script runs, it cannot (while the screen is locked by the screensaver), see the Command Prompt window to send the keypress to it. What I did to confirm this was to set the task to run not at 8pm, but two minutes from now. I then pressed Ctrl+Alt+Del and clicked on the 'lock screen' button. I then left the PC alone for two minutes, and then unlocked it - and sure enough, the Command Prompt was sitting there (so AutoIt had run that part of it ok), but the keypress had not been sent. It could be important to know that the screensaver part had not come on - I had just locked the PC. I haven't tested it as yet, so I'm not sure if the script would still fail if the screensaver was on, but the 'on resume, password protect' option was not selected. Most definitely, AutoIt fails when the PC/screen is locked. Anyway, can anyone tell me if this is a known limitation in AutoIt, and if there are any workarounds apart from disabling the screensaver?

Thanks,

CM

Forgive me for asking what may be a silly question, but wouldn't it be easier to just re-write the batch file in AutoIt and eliminate the probelm altogether?

Ralph

Share this post


Link to post
Share on other sites
romulous

Forgive me for asking what may be a silly question, but wouldn't it be easier to just re-write the batch file in AutoIt and eliminate the probelm altogether?

Ralph

Hi,

That's not a silly question. I guess I hadn't even thought that you might be able to do the backup script in AutoIt. The main thing for the purge.bat file would be the command to delete anything over 10 days old. I have no idea if AutoIt could do that, I will have to have a look through the AutoIt helpfile and see what you can do.

Regards,

CM

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  

×