Skip to content

Commit 5f12dc1

Browse files
committed
Fixed shutdown bug.
Fully switched over to Task Scheduler. Updated the version number to 2.0.0.0.
1 parent 7b1aade commit 5f12dc1

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0.0
1+
2.0.0.0

WindowsShutdownTimer.exe

512 Bytes
Binary file not shown.

WindowsShutdownTimer/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public Options(TimerForm parent)
3838
else
3939
{
4040
// Windows 7 doesn't have the last run time so I need to do something else.
41-
if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
42-
last_shutdown_label.Text = "N/A";
41+
if (timerWindow.GetLastRunTime(TimerForm.DEFAULT_TASK_NAME) == default(DateTime))
42+
last_shutdown_label.Text = Convert.ToString(Properties.Settings.Default.ShutdownTimer);
4343
else
4444
last_shutdown_label.Text = Convert.ToString(timerWindow.GetLastRunTime(TimerForm.DEFAULT_TASK_NAME));
4545
}

WindowsShutdownTimer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.4.1.0")]
36-
[assembly: AssemblyFileVersion("1.4.1.0")]
35+
[assembly: AssemblyVersion("2.0.0.0")]
36+
[assembly: AssemblyFileVersion("2.0.0.0")]

WindowsShutdownTimer/Timer.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public partial class TimerForm : Form
2626

2727
public const string DEFAULT_TIMER_DISPLAY = "0 days 0 hr 0 min 0 sec";
2828
public const string DEFAULT_TASK_NAME = "ScheduledShutdownTimer";
29-
private const string SHUTDOWN_COMMAND = "echo \"Hello!\" ";
29+
private const string SHUTDOWN_COMMAND = "/s /c \"Scheduled Computer shutdown via the Windows Shutdown Timer App\" /t 1";
3030

3131
/// <summary>
3232
/// Sets the initial program parameters.
@@ -94,7 +94,7 @@ public TimerForm()
9494
}
9595
catch (NoTimerExists)
9696
{
97-
StopLocalTimer(true);
97+
StopLocalTimer();
9898
}
9999
catch(Exception)
100100
{
@@ -378,7 +378,7 @@ private void CreateShutdownTimer(int numSeconds)
378378
td.Settings.Enabled = true;
379379

380380
td.Triggers.Add(new TimeTrigger(_shutdownTime));
381-
td.Actions.Add(new ExecAction("cmd.exe", SHUTDOWN_COMMAND + " seconds entered: " + numSeconds, null));
381+
td.Actions.Add(new ExecAction("shutdown", SHUTDOWN_COMMAND, null));
382382

383383
TaskService.Instance.RootFolder.RegisterTaskDefinition(DEFAULT_TASK_NAME, td);
384384

@@ -423,9 +423,25 @@ private void ModifyShutdownTimer(int numSeconds)
423423
}
424424
}
425425

426-
task.Definition.Settings.Enabled = true; // Resets the status of the task to Ready in case it was modified.
426+
// Add the new trigger after making sure it is the only one.
427427
task.Definition.Triggers.Add(new TimeTrigger(_shutdownTime));
428428

429+
if (task.Definition.Actions.Count == 1)
430+
task.Definition.Actions.RemoveAt(0);
431+
432+
else if (task.Definition.Actions.Count > 1)
433+
{
434+
for (int index = 0; index < task.Definition.Actions.Count - 1; index++)
435+
{
436+
task.Definition.Actions.RemoveAt(index);
437+
}
438+
}
439+
440+
// Add the new action after making sure it is the only one.
441+
task.Definition.Actions.Add(new ExecAction("shutdown", SHUTDOWN_COMMAND, null));
442+
443+
// Reset the status in case it was set as anything but "Ready"
444+
task.Definition.Settings.Enabled = true;
429445
task.RegisterChanges();
430446

431447
Properties.Settings.Default.ShutdownTimer = _shutdownTime;
@@ -642,14 +658,14 @@ private void time_remaining_timer_Tick(object sender, EventArgs e)
642658
}
643659
catch(NoTimerExists)
644660
{
645-
if (TimerDisabled(DEFAULT_TASK_NAME))
661+
if (TimerExists(DEFAULT_TASK_NAME) && TimerDisabled(DEFAULT_TASK_NAME))
646662
StopLocalTimer(true);
647663
else
648664
StopLocalTimer();
649665
}
650666
catch(TimerEnded)
651667
{
652-
if (TimerDisabled(DEFAULT_TASK_NAME))
668+
if (TimerExists(DEFAULT_TASK_NAME) && TimerDisabled(DEFAULT_TASK_NAME))
653669
StopLocalTimer(true);
654670
else
655671
StopLocalTimer();
@@ -816,7 +832,6 @@ private void notifyIcon_DoubleClick(object sender, EventArgs e)
816832
{
817833
RestoreForm();
818834
TimerForm_Resize(null, null);
819-
820835
}
821836

822837
/// <summary>

0 commit comments

Comments
 (0)