laneit 0 Posted November 6, 2014 Hi, I have a command line exe that I want to run unattended via the windows task scheduler. The program requires some input. I have compiled and it runs successfully when I run the program manually. However; when I set up in windows scheduler to run when I am logged off; it doesn't seem to work (looking at the log file I generated; it doesn't issue the 'send' command to the program. Run("c:windowssyswow64cmd /c ""d:myprogmyprog.exe -c d:myprog.config.txt >d:myprogsp.log"" ") WinWaitActive("c:windowssyswow64cmd.exe") Sleep(5000) Send("0{ENTER}all{ENTER}{ENTER}") Sleep(5000) Send("9{ENTER}") WinWaitClose("c:windowssyswow64cmd.exe") ; Finished! Share this post Link to post Share on other sites
MikahS 92 Posted November 6, 2014 (edited) Do you have it set to run with 'Run with highest privileges' on? EDIT: This post and topic could shed some light: >link Also, welcome to the AutoIt forum! Edited November 6, 2014 by MikahS Snips & ScriptsMy Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4Feel free to use any of my code for your own use. Forum FAQ Share this post Link to post Share on other sites
BrewManNH 1,304 Posted November 6, 2014 https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F 1 MikahS reacted to this 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 Share this post Link to post Share on other sites
13lack13lade 22 Posted November 7, 2014 (edited) i know how to fix your issue in fact mine does the exact same at work... If you run the script manually as in, through task scheduler right click and run does it execute? Try changing the setting from 'Run weather user is logged on or not' TO 'Run only when logged in' and it should work - it will still work when your computer is locked through this setting aslong as it is logged in Also if that doesnt solve the issue, change your 'Actions' to the following... Program/Script: cmd Add Arguments: /c start "" "filepath/to/your/script.au3" This should solve all your issues... Edited November 7, 2014 by 13lack13lade Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 Thanks. I have looked at a few examples and come up with the below. This still did not send the keys to the program - have I missed something? Ideally I need my script to be able to run when the user is logged off. Run("c:windowssyswow64cmd /c ""d:myprogmyprog.exe -c d:myprog.config.txt >d:myprogsp.log"" ")Run("c:windowssyswow64cmd /c ""d:endursp_olf_monitor.exe -c ndisnossrv01ENIITLApplicationsEndurPRDConfigspread_PRD.conf >d:endursp.log"" ") Local $hWnd = WinWait("c:windowssyswow64cmd.exe", "", 10) Sleep(3000) ControlSend($hWnd, "", "Edit1", "0{ENTER}all{ENTER}{ENTER}") Sleep(5000) ControlSend($hWnd, "", "Edit2", "9{ENTER}") controlsend($hWnd, "", "Edit3", "9") WinClose($hWnd) Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 Doesn't the program allow to pass the required data on the command line itself? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 Doesn't the program allow to pass the required data on the command line itself? Unfortunatly not. It needs the key press :-( Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 You could also pass the data using StdIn. Please check the help file for StdInWrite. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 You could also pass the data using StdIn. Please check the help file for StdInWrite. Thanks. I have tried this; but it still didn't send the keys. Do I have my code correct? #include <AutoItConstants.au3> Local $iPID = Run("c:windowssyswow64cmd /c ""d:myprogmyprog.exe -c d:myprog.config.txt >d:myprogsp.log"" ") sleep (2000) StdinWrite($iPID, "0" & @CRLF & "ALL" & @CRLF & @CRLF ) Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 In your example you use output redirection. Couldn't you use input redirection and store the needed information in a file? Local $iPID = Run("c:\windows\syswow64\cmd /c ""d:\myprog\myprog.exe -c d:\myprog.config.txt <d:\myprog\input.txt >d:\myprog\sp.log"" ") My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 In your example you use output redirection. Couldn't you use input redirection and store the needed information in a file? Local $iPID = Run("c:\windows\syswow64\cmd /c ""d:\myprog\myprog.exe -c d:\myprog.config.txt <d:\myprog\input.txt >d:\myprog\sp.log"" ") I had tried this but my program requires a press of the enter key and I could not achieve this with input redirection - hence I was suggested to use AutoIt. Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 The Enter key is simply @CRLF in the input file. Does your program accept input redirection? So we know if input redirection does not work or just the way Enter is being expected. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 The Enter key is simply @CRLF in the input file. Does your program accept input redirection? So we know if input redirection does not work or just the way Enter is being expected. It does accept direction from file but will not accept @CRLF as an input paramter. If I can get the StdinWrite or ControlSend working that would be perfect. Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 Taken the data you send from your first post I think the input file should look like:1: 02: all3:4: 95:The line numbers (e.g. 3:) need to be removed. I just added them for better readability. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 Taken the data you send from your first post I think the input file should look like: The line numbers (e.g. 3:) need to be removed. I just added them for better readability. I have tried this and the program doesn't accept the blank lines return character (so it gets stick on 'press enter to continue'). Code waits for n Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 The example in the help file for StdInWrite should give you a very good idea how it works. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
laneit 0 Posted November 7, 2014 Thanks. I have looked at the help file and written as follows. I still get no output written to the window. Where am I going wrong? #include <AutoItConstants.au3> #include <Constants.au3> Opt("WinTitleMatchMode", 2) Run("cmd /k d:myprogsp_olf_monitor.exe >d:myprogsp.log") Sleep(2000) Local $iPID = wingetprocess("cmd.exe") StdinWrite($iPID, "0{ENTER}all{ENTER}{ENTER}9") StdinWrite($iPID, "0" & @CRLF & "ALL" & @CRLF & @CRLF & "9" ) Share this post Link to post Share on other sites
water 2,359 Posted November 7, 2014 (edited) The keys you use are the keys expected by Contro* functions. Using StdInWrite you need to use ordinary keystrokes: #include <AutoItConstants.au3> #include <Constants.au3> $iPID = Run("cmd /k d:\myprog\sp_olf_monitor.exe >d:\myprog\sp.log") Sleep(2000) if $iPID = 0 Then Exit MsgBox(0, "Error", "Run returned error " & @error) StdinWrite($iPID, "0" & @CRLF & "all" & @CRLF & @CRLF & "9") Edited November 7, 2014 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites