LCote Posted May 11, 2018 Share Posted May 11, 2018 I am trying to automate a process which opens an exe, opens a window in that exe and runs. I can get the script to work when I am running it from the editor. I can get the script to work when I run it from the task scheduler as long as I have the window open to remote desktop. But, as soon as I close the window to remote desktop (note: just closing the window NOT logging off as the service user), the script fails. I have set up logging on my script so I know that one line "$handle1=WinGetHandle("VISUAL MRP(tm) - Material Requirements Planning - 615")" is not getting the handle. The fist part of the script runs fine. And the logging is working so I know that it is running some of the script. But I cannot get this handle to reliably be found. I have run this script several times in the editor and it is reliably finding the handle that way. Just not when I run it with the task scheduler and the RDP window closed. This has been ongoing for a few weeks now and I am not sure where to try next. Can anyone help? Link to comment Share on other sites More sharing options...
BrewManNH Posted May 11, 2018 Share Posted May 11, 2018 Please post your script, or a reproducer script that demonstrates what it is you're doing. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Earthshine Posted May 11, 2018 Share Posted May 11, 2018 (edited) PsExec is going to be your friend for running your scripts remote on vms and such. Edited May 11, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 #include <Date.au3> #include <array.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> $sFileName = "C:\Test.txt" ; Open file - deleting any existing content $hFilehandle = FileOpen($sFileName, $FO_OVERWRITE) FileWrite($hFilehandle,"Start"& @CRLF) AutoItSetOption ("TrayIconDebug", 1) ShellExecute("G:\Infor\Visual\Visual MFG\VMPLNWIN.EXE","-u <username> -p <password> -d <database>") FileWrite($hFilehandle, getcurrenttime() & "Execute Window"& @CRLF) sleep(3000) $handle=WinGetHandle("Material Planning Window - Infor VISUAL [Material Planning Window]") WinActive($handle) FileWrite($hFilehandle, getcurrenttime() & $handle & @CRLF) Send("!F") FileWrite($hFilehandle,getcurrenttime() & "send !f" & @CRLF) Sleep(1000) Send("{Down}") sleep(1000) Send("{Down}") sleep(1000) Send("{Down}") sleep(1000) Send("{Down}") sleep(1000) Send("{Down}") sleep(1000) Send("{Down}") sleep(1000) Send("{ENTER}") sleep(10000) FileWrite($hFilehandle, getcurrenttime() & "send enter line 36" & @CRLF) ;window is now open$handle1=WinGetHandle("VISUAL MRP(tm) - Material Requirements Planning - 615") ;AutoItSetOption("WinTitleMatchMode",4) ;$handle1=WinGetHandle("[CLASS:Gupta:Dialog; INSTANCE:1]") WinActivate($handle1) sleep(3000) WinActive($handle1) FileWrite($hFilehandle,getcurrenttime() & $handle1 & @CRLF) The line in blue is the line which is not working when unattended. This works FINE when I am watching the screen. Just not when the RDP window is not open. The script gets the handle of the first window just fine when the RDP window is not open. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 11, 2018 Share Posted May 11, 2018 You can't use Send, or WinActive or Activate on an unattended PC. https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 Okay, that is helpful. But now, how the heck do I use control send to send alt f? Link to comment Share on other sites More sharing options...
BrewManNH Posted May 11, 2018 Share Posted May 11, 2018 The same way you do with Send, just need the window handle or title and the control handle. The help file explains how it works. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 The help files are not particularly helpful at least for me. Can I send {DOWN} with controlsend? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 11, 2018 Developers Share Posted May 11, 2018 I would think it is pretty clear...no?: Quote Remarks ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 Ok. I tried to use ControlSend($handle,"","","{Down}") and it doesn't work. So, yes, that statement you posted is clear but this doesn't work. So I must be missing something. I Link to comment Share on other sites More sharing options...
jdelaney Posted May 11, 2018 Share Posted May 11, 2018 Alt + f altetnative: Winmenuselectitem IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 Yeah, I have tried that with no success either. The program I am trying to automate isn't the best engineered product. Link to comment Share on other sites More sharing options...
seandisanti Posted May 11, 2018 Share Posted May 11, 2018 14 minutes ago, LCote said: Ok. I tried to use ControlSend($handle,"","","{Down}") and it doesn't work. So, yes, that statement you posted is clear but this doesn't work. So I must be missing something. I When you use control send, you need to specify the control to which you're sending. Also it's a good idea to check for success on WinGetHandle etc, and you can often use the wait functions (WinWaitActive, winWaitNotActive, etc) to avoid guessing at sleep durations. Link to comment Share on other sites More sharing options...
jdelaney Posted May 11, 2018 Share Posted May 11, 2018 It will work when you take into account the accelerators. post what you tried IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
seandisanti Posted May 11, 2018 Share Posted May 11, 2018 Also, WinActive right after WinGetHandle is not necessary, and is probably not doing what you think it is, as you're not using it as a check of anything. Link to comment Share on other sites More sharing options...
jdelaney Posted May 11, 2018 Share Posted May 11, 2018 Example...this will not work for notepad.exe Winmenuselectitem ($h,"","File","Open...") This will: Winmenuselectitem ($h,"","&File","&Open...") Wherever you see the underscores, you need to include a & IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 #include <Date.au3> #include <array.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> $sFileName = "C:\Users\svc_erpvisual\Documents\Test.txt" ; Open file - deleting any existing content $hFilehandle = FileOpen($sFileName, $FO_OVERWRITE) FileWrite($hFilehandle,"Start"& @CRLF) AutoItSetOption ("TrayIconDebug", 1) ShellExecute("G:\Infor\Visual\Visual MFG\VMPLNWIN.EXE","-u <username> -p <password> -d <database>") FileWrite($hFilehandle, getcurrenttime() & "Execute Window"& @CRLF) sleep(3000) $handle=WinGetHandle("Material Planning Window - Infor VISUAL - [Material Planning Window]") FileWrite($hFilehandle, getcurrenttime() & $handle & @CRLF) sleep(1500) ControlSend($handle,default,$handle,"!F",0) Up to here, this works. I either need to send down several times. Or send "Q" or winmenuselect to get to the command and NONE of it is working. I am already aware of the ampersand in winmenuselect. That still isn't working for me. I have been all over Google about this. The only thing I haven't read about is the accelerators. Can you explain? Link to comment Share on other sites More sharing options...
jdelaney Posted May 11, 2018 Share Posted May 11, 2018 (edited) When you send alt at a window, you will see some letters are underlined in the menu. those are accelerators, letters you can send at the window to open the menu item. generally sub items in those menus also have accelerators. you must include a & in front of that underlined letter. read the full helpfile page for this (it's a link, click it): Winmenuselectitem Edited May 11, 2018 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
LCote Posted May 11, 2018 Author Share Posted May 11, 2018 (edited) Yes, I know that. But it isn't working. I am trying to send alt F then Q. It doesn't work. I have tried sending ControlSend($handle,default,$handle,"!F",0) ControlSend($handle,default,$handle,"Q",0) I also tried ControlSend($handle,default,$handle,"!FQ",0) None of these are working for me. It could easily be a problem with the software I am trying to automate. I also tried ControlSend($handle,default,$handle,"{down}") and that didn't work either. Edited May 11, 2018 by LCote Link to comment Share on other sites More sharing options...
jdelaney Posted May 11, 2018 Share Posted May 11, 2018 (edited) Those methods won't work on a locked desktop. i gave you the proper function to use that works in all situations Edited May 11, 2018 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. 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