Scheduling with the Windows Task Scheduler

Create recurring tasks with the Kantu command line and the Windows Task Scheduler. The Windows Task Scheduler is a very powerful task scheduling application that is built into any Windows version. The screenshots on this page are taken on Windows 10, but the task scheduler user interface has not really changed much the last years. So it is the same procedure on Windows 7 and Windows Server 2012R2 and Windows Server 2016. To open the task scheduler, you can use the Windows search box and search for it:

Windows Task Scheduler:

Next, select “Create Task” and the task scheduler wizard opens. It starts with the security tab: Top

Security Tab ("Runas")

This tab is important. Here you decide how your application is run- You have two plus one options:

  • “Run only when user is logged in”. This is the best option to TEST your macros, as then Chrome and Firefox (and with it, Kantu) will run under your user account, just like when you manually start it. It is visible and you can check if all works well. Once that works, you can change the settings to the background (headless) mode.
  • “Run whether user is logged in or not.” plus autologin: Use this option if your macro contains the real user commands XClick, XMove or XType.
  • “Run whether user is logged in or not.”. This is also called “headless mode". This option makes the Chrome or Firefox browser run as a background process, even when no user is logged in. We do not recommend to use this mode, as Chrome and Firefox are not designed to work in the background mode, and often show all kinds of strange issues when used this way. This is not a problem of Kantu, but is an issue of the browsers and website. That said, for many websites this mode works well (for example, automating ui.vision, ocr.space or e. g. a google search is no problem at all). Important: If you want to run Kantu in the headless mode, you must check the option Run with highest privileges so the web browser (and thus Kantu) can access the internet from its background process.

Windows Task Scheduler: Run Options (Security Settings)

When to use what task scheduler RUN option?

Kantu core itself can runs in headless mode just fine. But some Kantu commands - by their very nature - only work in user mode and/or an unlocked desktop. For example, real user simulation commands need an unlocked desktop, otherwise there is no mouse cursor or keyboard that it can control. A real human user can also not work with a locked desktop. The table below summarizes what Kantu feature works headless and which feature requires an open desktop. This applies to Windows, macOS and Linux.

Kantu Run Modes =>
Kantu feature:
Headless User needs to be logged in,
but screen can be locked
Desktop unlocked
Kantu Core Yes Yes Yes
Selenium IDE commands Yes Yes Yes
Visual UI Testing Yes Yes Yes
OCR Yes Yes Yes
Real User Simulation - - Yes
Desktop Automation - - Yes

Autologin on Windows 7, 10 and Windows Server 2016, Windows Server 2019

Autologin means that the machine unlocks the desktop after a reboot. In the Windows Run dialog box (Win Key + R), type Netplwiz and then press Enter key. Step 2: In the resulting User Accounts dialog, select your user account first and then uncheck the option labelled Users must enter a user name and password to use this computer. Click Apply button to see Automatically sign in box.

Autologin is of course also available on macOS and Linux.

Disconnecting From Remote Desktop While Running Macros with Real User Simulation

When using Remote Desktop to connect to a remote computer, closing Remote Desktop locks out the computer, displaying the logon screen. In the locked mode, the computer does not have GUI (active Window), so any currently running or scheduled Real User XClick, XMove and XType commands will fail (See also How To Run).

To avoid problems with RealUser commands, use the tscon utility to disconnect from Remote Desktop. tscon returns the control to the original local session on the remote computer, bypassing the logon screen. All programs on the remote computer continue running normally, including GUI tests.

To disconnect from Remote Desktop, run the following command on the remote computer (in the Remote Desktop window) as an Administrator:

%windir%\System32\tscon.exe RDP-Tcp#NNN /dest:console

where RDP-Tcp#NNN is the ID of your current Remote Desktop session, for example, RDP-Tcp#0. You can see it in the Windows Task Manager on the Users tab, in the Session column.

You will see the “Your remote desktop session has ended” message, and the Remote Desktop client will close. But all programs and tests on the remote computer will continue running normally.

Another option is to use Auto-Login and make sure your automation starts after a machine reboot. The macro autostart can be done e. g. with the Task Scheduler, just as described earlier on this page. In this case you can reboot the machine just before disconnecting the RDP session, and the Kantu macros will resume their work after the restart. This is what we use on our own test machines.

Top

Trigger Tab

On this tab you select when and how often you want to start the process. In this example the process starts at Windows starts and then runs every 5 minutes

Windows Task Scheduler: Run when (Trigger Settings)

Insider tip: Note that when you set a start time, e. g. 9:00 am and want to test it a bit later, maybe at 9:30am, nothing will happen for the next 23 hours. So the 9:00am start is not trigged until the next time it is actually 9am.

Top

Action Tab

Use the “browse” button to locate the program or script you want to start. If you want to use the Kantu command line directly, the program to start is Chrome or Firefox. Alternatively you can also start a Powershell or Python script, and then this script starts the browser with Kantu.

Windows Task Scheduler with Chrome

We recommend the "Start Kantu indirectly via a script" option (see the screenshot below), as this gives you more control and is easier to test and debug. You find example scripts for both languages in the Kantu github repo.

Windows Task Scheduler with PowerShell

Top

Settings Tab

Nothing to do here. If you selected “Run only when user is logged in” in on the first tab, just click. If you had chosen the “Run in background” option, the scheduler prompts you for the user name and password under which account Kantu should run. Make sure that Kantu has actually been installed in the user account that you enter here. That is all, the scheduled task is set-up.

Windows Task Scheduler: Enter password (Setting Settings :-)

Top

Test and debug Windows Task Scheduler

For testing, select the task, right-click on it and select “Run”. If you selected “Run only when user is logged in” in on the first tab, the browser and Kantu will now start and run the macro. If you had chosen the “Run in background” option, the browser and Kantu will also start, but you will see nothing, as it runs as background process.

Check return code

If a task ran successfully, the return code is "0x0":

Windows Task Scheduler: Check return value

Check background process

Moderate CPU usage, some file usage and some internet activity are the sign of a healthy instance of Kantu or the SeeShell browser:

Windows Task Scheduler: Find background process

The screenshot shows a SeeShell Browser instance. For Kantu, you can check the Chrome and Firefox processes, as Kantu "lives" inside these web browsers.

Questions? Suggestions? Kantu tech support can help.

Top
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.