laneit Posted November 6, 2014 Share 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! Link to comment Share on other sites More sharing options...
MikahS Posted November 6, 2014 Share 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 & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
BrewManNH Posted November 6, 2014 Share Posted November 6, 2014 https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F MikahS 1 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...
13lack13lade Posted November 7, 2014 Share 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 Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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) Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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 :-( Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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 ) Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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. Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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. Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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 Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
laneit Posted November 7, 2014 Author Share 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" ) Link to comment Share on other sites More sharing options...
water Posted November 7, 2014 Share 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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