Before setting up the scheduling, please make sure to carefully read this article to make sure that you have properly prepared your projects for scheduling.
First, we go through the basics of making the batch files, then, at the end of the article, it is explained how the scheduling is set up in the Windows Task Scheduler.
Use Automation Orchestrator
We highly recommend to use the Automation Orchestrator instead of writing your own batch files. Only if you are experienced working with the Windows Task Scheduler and writing batch files should you consider this approach.
Getting started
A batch file is a simple text file created in Notepad. However, instead of having a .txt file extension, it should have a .bat extension. Foxtrot and FoxBot allows you to run your projects through batch files, allowing you to schedule or trigger the automation as you desire.
Here is a simple example. Simply open Notepad and write a similar line in order to open Foxtrot and run a project. In below example, the Foxtrot program is installed in the "Program Files (x86)" folder and the project to open and run is "C:\ProgramData\Foxtrot Suite\Run Script v1.fox".
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
The logic of the batch file is as shown below. It is important to notice that the name of the application and the path of the application is surrounded by quotation marks, whereas the path to the project file is not.
"Path to Foxtrot/FoxBot.exe" /Open Project Path /Run
Here is a list of the support commands that can be added with a brief description of each:
Command |
Description |
/Add |
Adds a database to the Project. |
/Close |
Closes the Project. |
/Exit |
Closes Foxtrot RPA. |
/Mark |
Marks specific records in the database. |
/Open |
Opens a Project. |
/Remove |
Removes the currently loaded database. |
/RunMode |
Sets the Run Mode that will be used when running the script. |
/RunSpeed |
Sets the Run Speed that will be used when running the script. |
/Run |
Runs the script. |
/SetStartup |
Temporarily sets a Task as the Startup Task. |
/Silent |
Instructs Foxtrot RPA to enter silent mode. |
/Unmark |
Unmarks specific records in the database. |
Please note that commands must always start with a "/" character, not a "\" character. Space must be used before each command and all commands must be on a single line.
Running multiple projects
It is important to know that in one batch file, it is possible to run multiple projects in a sequence, meaning that after the first is complete, the second will start, etc. To do this, you simply add the commands after each other like this:
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run /Close /Open C:\ProgramData\Foxtrot Suite\Run Script v2.fox /Run
Batch file for scheduling
There are a few things to consider in terms of the batch file if you wish to schedule it. When the scheduled job is started, there is a chance that Foxtrot/FoxBot is in the middle of execution, so you need to decide what should be done it that case.
- Kill the running Foxtrot/FoxBot before starting the scheduled job
- Wait for the running Foxtrot/FoxBot to close before starting the scheduled job
- Simply do not start the scheduled job if Foxtrot/FoxBot is running (mostly relevant in this case)
IMPORTANT: If running your automation on a server where there can (potentially) be more than on active users, working with processes is a bit more complicated as you will have to make sure that the process is running on the user you are interested in. Because, otherwise, you risk taking a decision based on the process running on a different user - and you even risk killing the process of Foxtrot or FoxBot running on a different user without intending to. Therefore, please be aware of this fact and implement a suitable solution to deal with this in the case that you are working on a server.
Here is some explanation on how to do the three different things. For more information on how to work with the list of tasks running on a machine, please reference below article:
Kill the running Foxtrot/FoxBot
If working on a server with potentially multiple active users, please remember to consider the points explained above. Notice that in below example we use "/FI "USERNAME eq %username%"" to only work with the current user.
To kill Foxtrot:
taskkill /F /FI "USERNAME eq %username%" /IM foxtrot.exe
TIMEOUT 5
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
To kill FoxBot:
taskkill /F /FI "USERNAME eq %username%" /IM foxbot.exe
TIMEOUT 5
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\FoxBot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
Wait for the running Foxtrot/FoxBot to close
If working on a server with potentially multiple active users, please remember to consider the points explained above. Notice that in below example we use "/FI "USERNAME eq %username%"" to only work with the current user.
Wait for Foxtrot:
:LOOP
tasklist /FI "USERNAME eq %username%" | find /I "FOXTROT" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO Foxtrot is still running
TIMEOUT 5
GOTO LOOP
)
:CONTINUE
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
Wait for FoxBot:
:LOOP
tasklist /FI "USERNAME eq %username%" | find /I "FOXBOT" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO FoxBot is still running
TIMEOUT 5
GOTO LOOP
)
:CONTINUE
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\FoxBot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
Do not start the scheduled job if Foxtrot/FoxBot
If working on a server with potentially multiple active users, please remember to consider the points explained above. Notice that in below example we use "/FI "USERNAME eq %username%"" to only work with the current user.
Start Foxtrot if it is not already running:
tasklist /FI "USERNAME eq %username%" | find /I "FOXTROT" >nul 2>&1
IF ERRORLEVEL 1 (
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
) ELSE (
ECHO Foxtrot is still running
)
Start FoxBot if it is not already running:
tasklist /FI "USERNAME eq %username%" | find /I "FOXTROT" >nul 2>&1
IF ERRORLEVEL 1 (
"C:\Program Files (x86)\Foxtrot Suite\Foxtrot\FoxBot.exe" /Open C:\ProgramData\Foxtrot Suite\Run Script v1.fox /Run
) ELSE (
ECHO FoxBot is still running
)
Checking the tasklist on a remote machine
If you need to evaluate the tasklist not on the local machine but on a remote machine, which is useful if you need to start scripts on remote machines using the below explained method, you simply have to specify the name of the machine/server like this: "/S machinename"
tasklist /S machinename /FI "USERNAME eq username"
Where you obviously need to change the "machinename" and "username".
Start Foxtrot or FoxBot on a remote machine
In some cases, you need to do central management of your automation and are looking to make the set up on one machine and distribute the work to other machines. This is an in-built feature in FoxHub, and this is also something you can achieve using batch files.
The first step is to download the PsExec tool available in the PsTools package made by Microsoft. Simply download the PsTools zip file, unzip it, and we recommend placing the PSTools folder on the C: drive like this: "C:\PSTools"
It should look like this. Whether you keep the other tools from the PsTools package is up to you.
Now, you may find all the official documentation on how to use the PsExec tool on the same page via the above link. The tool will allow you to specify that the given command that you wish to initiate should not be on your own PC but on another specified machine. Of course, just like with the FoxHub, this machine needs to be in your domain and network, and you need to be able to access it.
This procedure is a bit more advanced a takes some trial and error to get right as you need to understand how you appropriately connect to the given machine and session. In the below image, the manual process of investigating how to properly connect to the server "BCODKFOX01" on user "basico\mbalslow" is illustrated.
First, you make sure that your CMD is in the folder of your PsTools. You do this with this command.
cd c:\PSTools
Hereafter, you can use the psexec.exe tool. The first thing we do is connect to the machine and retrieve a list of all active sessions. This is necessary as this example is dealing with a server where multiple sessions can be active at the same time.
IMPORATNT: You always need to write "\\" before the name of the machine that you need to connect to.
IMPORTANT: Writing username and password is not always necessary. You can start by testing without specifying it to see if it works.
psexec.exe \\MACHINENAME {-u X -p Y} query session
Now when you know the session ID, you can use that in the last command to start Foxtrot/FoxBot. The three dots "..." is where you then write whatever command you need in order to start your Foxtrot or FoxBot.
psexec.exe \\MACHINENAME {-u X -p Y} -d -i SESSIONID ...
See below two screenshots. In below screenshot, we simply open the Foxtrot application, we do not actually start a project or anything else. The cmd prompt is running on the local machine and the second screenshot is of the server "BCODKFOX01" where Foxtrot is successfully opened.
So, how could you implement this dynamically in a batch file that you wish to schedule? Here is the best-practice way to construct your batch file.
cd c:\PSTOOLS && for /f "tokens=2-4" %a in ('psexec.exe \\MACHINENAME query session') do @if "%a"=="USERNAME" if "%c"=="Active" psexec.exe \\MACHINENAME -d -i %b ...
Let's break it down!
The first part is simply making sure that we navigate to the path of the PsTools. The "&&" is how you instruct it to perform the command and then continue to the next one.
cd c:\PSTOOLS &&
Then we construct a loop to retrieve the session information for the specific user we are interested in to extract the session ID. Also, we make sure to only continue if this user is active, meaning that there is an active session/connection to this user. Of course, you could implement an action to do something in an "else" if the given user is not found or not active.
for /f "tokens=2-4" %a in ('psexec.exe \\MACHINENAME query session') do @if "%a"=="USERNAME" if "%c"=="Active"
The last part after inside of the if-statement is then to start Foxtrot or FoxBot on the given user using the extracted session ID. The "%b" is the extracted session ID.
psexec.exe \\MACHINENAME -d -i %b ...
So, to put this into context of the above screenshot examples, this would be how the batch file should look. Remember, in the very last part, we are simply opening Foxtrot, not actually starting any project, which is something you of course would want.
cd c:\PSTOOLS && for /f "tokens=2-4" %a in ('psexec.exe \\BCODKFOX01 query session') do @if "%a"=="mbalslow" if "%c"=="Active" psexec.exe \\BCODKFOX01 -d -i %b "C:\Program Files (x86)\Foxtrot Suite\Foxtrot\Foxtrot.exe"
That's it! That's how you can also start your automation on a different machine.
Schedule the Project
Once a batch file has been created, it can be scheduled to run at a specific time using the Windows Task Scheduler. Below are the steps to schedule the task in Windows.
- Begin by opening the application "Task Scheduler"
- In this application, this is where you can add, edit, and run scheduled tasks on your Windows machine. To create a new scheduled task for your Foxtrot batch file, click to create a new "Basic Task"
- When the "Create Basic Task Wizard" appears, enter an appropriate name and description.
- On the next page, this is where you select the "Trigger" for the task. This can be a specific time, like a schedule, or you can decide to start your project, for example, when the user logs in. In this example, we will select the option to start the Foxtrot project daily. You can always adjust this at a later time.
- On this next page, this is where you set up your settings for the selected trigger. Because we selected daily, we need to specify what date it should start and at what time. Also, we need to specify how often it should recur.
- Now it is time to specfiy what should happen when the task is triggered. Select the option "Start a program".
- On this next page, we specify that the program to be started is the batch file that you have created to start Foxtrot or FoxBot and run the project.
- That's it! Now you have scheduled a task in the Windows Task Scheduler.
- You can always see the list of all your scheduled tasks here.
- We definitely suggest, to be sure that your task works properly, to right-click on the task and click "Run". This will trigger the task to start now. This way, you can be sure that it will open Foxtrot or FoxBot and start the project properly.
- To edit a task, simply right-click on it and select "Properties". Imagine, for example, that the job we just created should not run every day but only on weekdays. So, we need to edit the trigger that we have set up. Open the scheduled task, go to "Triggers" to edit the daily trigger to be a "Weekly" trigger instead and then it is possible to specify the days during the week that it should run.
Comments
0 comments
Please sign in to leave a comment.