Shutdown PC using the CMD command in Visual Studio C #

-1

I have a textbox called txtMinuto and a button called btnApagar . I want to use the command SHUTDOWN -s -t that is used to turn off the PC at a predetermined time but when I run my line of code to turn off the PC according to the time I entered in my textbox.

My line of code is not running correctly:

private void btnApagar_Click(object sender, EventArgs e)
        {
            int tiempo;
            int _result=0;
            String _minuto = txtMinuto.Text;
            tiempo = Convert.ToInt32(txtMinuto.Text);
            if (_minuto != "")
            {
                _result = (tiempo * 60);
            }
            System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe","SHUTDOWN -s -t "+ _result);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
        }
    
asked by Jhon H. 19.09.2017 в 22:47
source

1 answer

1

This works well for me

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

It would only be a matter of adding the textbox to the time parameter, something like that,

Process.Start("shutdown", "/s /t '"+ int.Parse(textBox1.Text) +"'");
    
answered by 19.09.2017 / 22:58
source