Search code examples
user-interfaceautomationscheduled-tasksdatetimepickerui-automation

C# application automation


i have a windows forms application to backup certain files. Normally you hit the button "Start Backup" and the programm will do whatever is selected as an option.

Now i have implemented via Task Sceduler DLL the possibility to do the backup on a desired day and time via a datetimepicker object.

So far i only found out how to register the the programm.exe in Windows and it also starts up on the chosen time.

My question now is how would it be possible to be able to execute the "Start Backup" button via automation or a script? All other needed parameters for the programm are stored in Settings.Default values.

Code from the Task Scheduler, maybe there is a shorter way to solve the problem?

        private void futureBackup_Click(object sender, EventArgs e)
    {
        dateTimePicker1.Format = DateTimePickerFormat.Time;
        TaskService ts = new TaskService();
        TaskDefinition td = ts.NewTask();
        Trigger t = new TimeTrigger();
        t.StartBoundary = System.DateTime.Now.Date
        +this.dateTimePicker1.Value.TimeOfDay;
        td.Triggers.Add(t);
        string path1 = Desktop + @"\Desktop\Release\Backup.exe";
        td.Actions.Add(new ExecAction(path1, null, null));
        ts.RootFolder.RegisterTaskDefinition("XBackupX", td);
        ts.BeginInit();
    }

I found the UI Automation in Visual Studio but i am not exactly sure if that's what can fix the "problem"!?!

Thank you in advance


Solution

  • for now the easiest way i came up with is to have 2 programm exe files... 2nd one is called backup_s.exe which then is added to the task scheduler in windows.

    only difference between the 2 codes is _s loads the last options automatically from an xml file then executes the start backup by trigger event and closes itself after 1 minute.