Friday, September 3, 2010

C# Tutorial: Create a Simple Shutdown Manager

Here is the code

using System.Diagnostics;
///////////////////////////////////////////
String shutdown;

/////////// Start Button //////////////////
Process.Start("Shutdown", shutdown + " -t " + textBox1.Text + @" -c ""Windows is going to shut down!"""); // -t = time , -c = comments
timer1.Start(); label3.Text = textBox1.Text;
 
/////////// Abort Button //////////////////
Process.Start("Shutdown", "-a"); timer1.Stop(); // -a = abort

/// ComboBox_SelectedIndexChanged Event ///
switch (comboBox1.SelectedIndex)
{
    case 0: shutdown = "-s"; break; // -s = shutdown
    case 1: shutdown = "-r"; break; // -r = restart
    case 2: shutdown = "-l"; break; // -l = log off
}

/////////// Timer_Tick Event //////////////
label3.Text = (Convert.ToInt32(label3.Text) - 1).ToString();

// NOTE: Exiting the program will NOT abort the shutdown! You must press the "Abort" button before exit!
// If you forgot to abort the shutdown don't worry! Open Command Prompt and type in "shutdown -a" (without quotes)!

Or download the solution

1 comment:

  1. when I do all that, it just posts me an error screen saying "Cannot find the file specified"...

    ReplyDelete