How-to trigger automation using the GUI Scheduler

Swaroop Koshy Mathew
2 min readNov 1, 2020

Automation is the creation and application of technologies to produce and deliver goods and services with minimal human intervention.

Automation scripts might need to be run on an ongoing basis or scheduled to be executed at certain intervals. Scripts to be executed at intervals can be set up through task schedulers.

Have you faced any issue where your scripts were not executed but the scheduler shows that the process was run successfully?

You would have faced this issue if your scripts need to open a browser to run your site to execute the scripts. One option to resolve this would be to use ‘headerless’ chrome scripts, but many would also have faced the issue with its method too. On research, I found that it requires a GUI to trigger a GUI executable file.

Solution: Usage of Windows Forms

We will use windows forms as a scheduler to trigger the automation scripts.

How to?

Step 1: Create a Windows Forms Project

Step 2: Add Timer Component from the toolbox

The added timer will be displayed in the footer of the project.
The timer will be disabled by default. We need to enable the Timer from the properties section. You can also set intervals when the application should trigger the executable file.

Step 3: Add the commands to be executed in the App.config file.

<add key=”Command1” value=”D:”/>
<add key=”Command2” value=”cd D:\MyProject\bin\debug”/>
<add key=”Command3” value=”myProject.exe”/>

Ensure you commands are working fine in command prompt before adding them to the application.

Step 4: Code for Executing the .exe file of the automation script through command prompt.

Process process = new Process();
process.StartInfo.FileName = “cmd.exe”;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
var cmd1 = ConfigurationSettings.AppSettings[“Command1”].ToString();
var cmd2 = ConfigurationSettings.AppSettings[“Command2”].ToString();
var cmd3 = ConfigurationSettings.AppSettings[“Command3”].ToString();
process.StandardInput.WriteLine(cmd1);
process.StandardInput.WriteLine(cmd2);
process.StandardInput.WriteLine(cmd3);
process.StandardInput.Flush();
process.StandardInput.Close();
Console.WriteLine(process.StandardOutput.ReadToEnd());

Build and deploy the application. The application should be left running, for the scheduler to be triggered. Logs can be added to monitor the execution.

Hope this article has been helpful.

Happy Coding!!

--

--