powdered toast man Posted July 25, 2006 Share Posted July 25, 2006 I have a script (code is below) that I want to run on a locked PC at 2 or 3 in the morning every day. I've just started using Autoit and the script I have works. It just doesn't run completely when the computer is locked and I have scheduled it to run under Windows Schedule Tasks. For some reason it pauses after the Run command for both dos and notepad. When I log back in, I see that the script is paused in the system tray. If I click on the dos console or notepad window, the script resumes. I tried to fix this with WinActivate but that doesn't seem to work. I know that others have mentioned ControlSend in the forums and I've tried it but it didn't work. Maybe I messed up the control id? If anyone can help me, you will be my hero! Plus, if you have any other ideas about my code, I'm open to that as well. I'm a newbie so I'd like to learn from any of my mistakes! Thanks in advance! Global $user = "user", $pass = "pass", $ftp = "ftp address" AutoItSetOption("SendKeyDelay", 200) ; use this if you want to slow down the keystrokes to see what is happening Run(@ComSpec & " /c " & $ftp, "", @SW_MAXIMIZE) ; Open FTP connection Sleep(5000) WinActivate("C:\WINDOWS\system32\cmd.exe","") Sleep(5000) WinSetState("C:\WINDOWS\system32\cmd.exe","",@SW_MAXIMIZE) Send($user & "{ENTER}" & $pass & "{ENTER}") ; Enter username and password Sleep(2000) Send("dir{ENTER}") ; List files in directory mouse() $report = ClipGet() ; Copy screen to clipboard Sleep(2000) Send("quit{ENTER}") ; Quit Sleep(2000) Run("notepad.exe") ; Run Notepad WinWaitActive("Untitled - Notepad") ; Wait for the Notepad become active Send("^v") ; Now that the Notepad window is active type ftp dir text Sleep(2000) Send("^s") ; Now save by pressing Ctrl + S Sleep(2000) Send("X:\FTP_REPORT") ; Save FTP_REPORT file to X drive Sleep(2000) Send("{ENTER}") Sleep(2000) Send("{LEFT}") ; Yes, save this file over existing file Sleep(2000) Send("{ENTER}") ; Yes, save this file over existing file Sleep(2000) Send("!f") ; Access File on menu above Sleep(2000) Send("x") ; Close Notepad WinWaitClose("FTP_REPORT") Exit ;functions Func mouse() ; function used to copy ftp screen to clipboard MouseClick("right", 75, 75, 1) Sleep(1000) Send("{DOWN 4}") Sleep(1000) Send("{Enter}") Sleep(1000) Send("{Enter}") EndFunc Link to comment Share on other sites More sharing options...
gamerman2360 Posted July 25, 2006 Share Posted July 25, 2006 (edited) Don't know much about ftp. But to write the file you can skip notepad and just do a FileWrite(). Edit: Ah, ok. The cmd starts up IE (or whatever browser). Could just run "iexplorer ftp://...". At least I think thats what it does. Edit2: Ok, I don't know about FTP. I was thinking since interfacing with other programs wasn't working, we could do something more direct. At FileWrite() works, so we don't need notepad. I was thinking I could look at how FTP worked. So I captured a few FTP packets between some server and IE. First I thought it was going to be simple (Things like "Here comes the directory listing." and "Please try to use a mirror if at all possible." were being sent.) but when I read the data (eg. "-rw-r--r-- 1 ftp"), I learned it was a project for another day. Also checked FTP.au3 but it only have things to manage the ftp server. Edited July 25, 2006 by gamerman2360 Link to comment Share on other sites More sharing options...
powdered toast man Posted July 25, 2006 Author Share Posted July 25, 2006 thanks gamerman for trying... i really just need to understand why the script pauses when it is locked but somehow is able to run through the script anyway and run both the cmd and notepad. when i go back to my computer and unlock it, i see the autoit script flashing in the system tray, i right click, and it says that it is paused. i unpause it and the script runs. is there some process that might be affecting this? i forgot to mention that i'm running this on an xp machine. Link to comment Share on other sites More sharing options...
MHz Posted July 25, 2006 Share Posted July 25, 2006 Any function that is dependant on an Active Window will fail with a locked PC. Your script would need a rewrite to use functions that do not require active windows, such as WinWait, Control* functions... Link to comment Share on other sites More sharing options...
powdered toast man Posted July 25, 2006 Author Share Posted July 25, 2006 So i should try something like this... WinWait("C:\WINDOWS\system32\cmd.exe") ControlSend("C:\WINDOWS\system32\cmd.exe","","",$user & "{ENTER}" & $pass & "{ENTER}") ; Enter username and password I can't find any control id for cmd when I use the AutoInfo tool so I left it blank in ControlSend. However, I tried the above on a locked PC and it still didn't work... I replaced all of the sends with controlsends and added the winwait like you said. Link to comment Share on other sites More sharing options...
MHz Posted July 25, 2006 Share Posted July 25, 2006 (edited) I'm not much of a believer in automating a command window as being unreliable. The FTP commandline executable supports using a text file with predetermined commands. Perhaps this would be a better idea. The script could write the text file, execute FTP and pipe the results to logfile. Just an idea. Edit: -s:FileName Specifies a text file that contains ftp commands. These commands run automatically after ftp starts. This parameter allows no spaces. Use this parameter instead of redirection (<). Edited July 25, 2006 by MHz Link to comment Share on other sites More sharing options...
powdered toast man Posted July 25, 2006 Author Share Posted July 25, 2006 I see what you are talking abouthttp://www.microsoft.com/resources/documen...p.mspx?mfr=trueI didn't see anything about the log file though? I just wanted a screenshot of the dir to see if files had been moved according to another automation program... how do you save the log file to a specified location?Plus, I have other scripts that use telnet to access a character based system... would this work for those scripts too?It sucks though, this script works fine when I run it when I'm logged in... I just need it to stop pausing when the computer is locked. Link to comment Share on other sites More sharing options...
powdered toast man Posted July 26, 2006 Author Share Posted July 26, 2006 i searched the forums a while back and found a solution which someone used for dealing with a locked computer. it used a fake prompt/logon screen that could be unlocked by an autoit script? does anyone know where this post is? i can't seem to find it now... ugghhh! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now