Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions SharpStay/SharpStay/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Xml;
using System.Linq;
Expand Down Expand Up @@ -199,7 +199,7 @@ static void ElevatedRegistryUserInitKey(string binpath, bool cleanup = false)
}

// Scheduled Task Items
static void CreateScheduledTask(string taskName, string command, string runasuser, string triggertype, string author, string description, string rep, string attime, string startat, string logonuser)
static void CreateScheduledTask(string taskName, string command, string runasuser, string triggertype, string author, string description, string rep, string attime, string startat, string logonuser, int expire)
{
List<string> retcmd = ParseCommand(command);
string Directory = retcmd[0];
Expand Down Expand Up @@ -238,14 +238,25 @@ static void CreateScheduledTask(string taskName, string command, string runasuse
trigger.Repetition.Interval = repetition;
trigger.StartBoundary = sbound;
//trigger.EndBoundary = "2020-01-31T12:00:00";
if(expire != -1)
{
DateTime currentDateTime = DateTime.Now;
DateTime expireTime = currentDateTime.AddDays(expire);
trigger.EndBoundary = String.Format(expireTime.ToString("yyyy-MM-dd" + "T12:00:00"));
}
}
else if (triggertype.ToLower() == "daily")
{
IDailyTrigger trigger = (IDailyTrigger)task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY);
trigger.Id = "DailyTrigger";
//trigger.Repetition.Interval = "PT2M";
trigger.StartBoundary = sbound;
//trigger.EndBoundary = "2020-01-31T12:00:00";
if (expire != -1)
{
DateTime currentDateTime = DateTime.Now;
DateTime expireTime = currentDateTime.AddDays(expire);
trigger.EndBoundary = String.Format(expireTime.ToString("yyyy-MM-dd" + "T12:00:00"));
}
}
else if (triggertype.ToLower() == "weekly")
{
Expand All @@ -256,6 +267,12 @@ static void CreateScheduledTask(string taskName, string command, string runasuse
// By default Monday-Friday
trigger.DaysOfWeek = 62;
trigger.WeeksInterval = 1;
if (expire != -1)
{
DateTime currentDateTime = DateTime.Now;
DateTime expireTime = currentDateTime.AddDays(expire);
trigger.EndBoundary = String.Format(expireTime.ToString("yyyy-MM-dd" + "T12:00:00"));
}
}
else if (triggertype.ToLower() == "monthly")
{
Expand All @@ -267,6 +284,12 @@ static void CreateScheduledTask(string taskName, string command, string runasuse
// By default 1st and 15th
trigger.DaysOfMonth = 16385;
//trigger.MonthsOfYear = 4095;
if (expire != -1)
{
DateTime currentDateTime = DateTime.Now;
DateTime expireTime = currentDateTime.AddDays(expire);
trigger.EndBoundary = String.Format(expireTime.ToString("yyyy-MM-dd" + "T12:00:00"));
}
}
else if (triggertype.ToLower() == "idle")
{
Expand Down Expand Up @@ -1268,6 +1291,7 @@ static void Main(string[] args)
string attime = "10:00:00";
string startat = "2017-07-01";
string rep = null;
int expire = -1;
if (arguments.ContainsKey("cleanup") && !arguments.ContainsKey("taskname"))
{
HowTo();
Expand Down Expand Up @@ -1306,7 +1330,11 @@ static void Main(string[] args)
{
startat = arguments["logonuser"];
}
CreateScheduledTask(taskname, arguments["command"], runasuser, arguments["triggertype"], author, description, rep, attime, startat, logonuser);
if (arguments.ContainsKey("expire"))
{
expire = Int32.Parse(arguments["expire"]);
}
CreateScheduledTask(taskname, arguments["command"], runasuser, arguments["triggertype"], author, description, rep, attime, startat, logonuser, expire);
}
}
else if (arguments["action"].ToLower() == "listscheduledtasks")
Expand Down