This project has moved and is read-only. For the latest updates, please go here.

Create task start time from datetimepicker, and execaction multiple arguments

Topics: Errors
Mar 8, 2013 at 9:05 AM
Edited Mar 8, 2013 at 10:46 AM
Hi, i have created a form in VS2012 with textboxes to enter starttime (as 00:00) and a datetimepicker.
Can i pass this into the timetrigger?
I have this:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy, MM, dd";
            string starttime = TB_starttime.Text;
            string startdate = dateTimePicker1.Text;
taskdDef.Triggers.Add(new TimeTrigger(new DateTime(2012, 12, 31)));

I tried as
taskdDef.Triggers.Add(new TimeTrigger(new DateTime stardate)));
but it doesn't work.

Also if i try to use more than 2 arguments on
askdDef.Actions.Add(new ExecAction("c:\script.ps1", "arg1" + dateTimePicker1, "arg2" + username, "arg3" + newsitecode, "arg4" + starttime ));

I get an error saying
microsoft.win32.taskscheduler.execaction does not contain a contructor that takes 4 arguments

Can i add more than 2 arguments?
Thanks
Mar 8, 2013 at 5:19 PM
For the time trigger, you must supply a valid DateTime value as the only argument to the constructor:
taskDef.Triggers.Add(new TimeTrigger(new DateTime(dateTimePicker1.Value)));
For the action, the first argument is the executable (or script) and the second is a single string argument that contains the entire string passed to the executable:
taskDef.Actions.Add(new ExecAction("c:\script.ps1", "arg1" + dateTimePicker1.Value.ToString() + "arg2" + username + "arg3" + newsitecode + "arg4" + starttime));