@@ -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