-2

i'm having trouble finding enough resources to create the windows form application that i want.As title says i want to create an application on which i can set a timer to shutdown computer.Any example or help would be appreciated.Regards

Edit:so i've mananged to put current date/time button and individual shutdown button the problem is i dont know how to set a timer on shutdown during the program is running.

Heres what i've put so far:

public partial class Form1 : Form { public Form1() { InitializeComponent(); }

    private void buttonTimerStart_Click(object sender, EventArgs e)
    {
        timer1.Start();

    }


    private void timer1_Tick(object sender, EventArgs e)
    {
        labelDate.Text = DateTime.Now.ToString();
    }

    private void buttonTimerStop_Click(object sender, EventArgs e)
    {
        timer1.Stop();
    }

    private void buttonShutdown_Click(object sender, EventArgs e)
    {
        Process.Start("Shutdown", "-s -t 0");

    }
user1849839
  • 7
  • 1
  • 2
  • 3
    [Try this.](http://www.google.com) – Rayshawn Nov 24 '12 at 17:12
  • You really need to try this yourself. For starters I would research timers, how to start a Process and search on google for what the DOS command is to shutdown a computer. And if this is homework it should be clearly marked as such. No one will do the work for you, we are here to help if you get stuck but this isn't a free coding site. – zeencat Nov 24 '12 at 17:15
  • 1
    @zeencat homework tag is forbidden – RvdK Nov 24 '12 at 17:18
  • @zeencat - I agree with you sentiment ...try something, show us what you've tried. Questions, however, shouldn't be marked homework anymore; right or wrong the tag is deprecated (http://meta.stackexchange.com/questions/147100). – EBarr Nov 24 '12 at 17:21
  • This is not an actual homework,i'm new to programming and i been resarching about this for an hour.I get what you say i don't expect ppl to do the work for me or free codding my purpose was recieving helpfull links from ppl who are familiar with this thats all.. – user1849839 Nov 24 '12 at 17:29
  • I'll put more effort and post it here.Thanks for suggestions – user1849839 Nov 24 '12 at 17:33

2 Answers2

0

I think this can help : How to shut down the computer from C#

Process.Start("shutdown","/s /t 0");

For the timing use the Windows form 'Timer'

Community
  • 1
  • 1
ahmadmanga
  • 29
  • 1
  • 10
  • I don't think you should of give the questioner even this amount of information. This is clearly homework and they have done next to no research. A quick google would of brought back as much information. – zeencat Nov 24 '12 at 17:17
  • in .NET use the Timer and make variable "T" ,each time the timer ticks make the variable t += 1 , after the T gets the amount you want of time do the shutdown code. – ahmadmanga Nov 24 '12 at 17:18
0

Basically one way to do it is to execute the windows shutdown executable and pass to it whatever timer parameters you want from your C# program. To execute any external program including this one from within your C# program you'll have to create a process, assign an executable to that process and start it something like this:

string path =  @" C:\Windows\System32";
string shut_args =  " ";

process1.StartInfo.FileName =  " shutdown.exe";
process1.Start();

Here is a very detailed tutorial that shows exactly what you want to do: http://www.codeproject.com/Articles/22718/Shutdown-Remote-Using-Shutdown-exe

Ayman Farhat
  • 2,010
  • 3
  • 17
  • 16