none
Shutting down using Process.Start results in restart RRS feed

  • Question

  • Hi, I used the following code to shutdown the PC:

    var psi = new ProcessStartInfo("shutdown", "/s /t 0");
    psi.CreateNoWindow = true;
    psi.UseShellExecute = false;
    Process.Start(psi);
    

    On my PC, it does shutdown.

    On the single-board-computer (SBC) running Windows 7 Professional, it restarts.

    If I type in "shutdown /s /t 0" in a CMD window on that SBC, it does shut down.

    What is the problem?

    Monday, October 17, 2016 5:37 AM

Answers

  • If possible, try invoking “shutdown” indirectly:

      var psi = new ProcessStartInfo( "cmd", "/C shutdown /s /t 0" );

      //psi.CreateNoWindow = true;

      psi.UseShellExecute = false;

      Process.Start( psi );

    Try with visible window first.

    • Marked as answer by Silan Liu Saturday, December 10, 2016 12:48 AM
    Monday, October 17, 2016 6:28 PM
  • No it is not about SBC or hardware. Please read my post. It is so short.

    This is about the specific behavior of the shutdown command under specific circumstances. Not really a programming question, but a Windows one.

    As my only guess, I would say that the lack of an interactive session let's shutdown trip up somehow. Either it does not properly set the "actually halt when done" tag properly, or there is a BSOD case with automatic restart (as CoolDadTx said).


    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    • Marked as answer by Silan Liu Saturday, December 10, 2016 12:48 AM
    Tuesday, October 18, 2016 11:17 AM

All replies

  • Hi Silan Liu,

    This forum is discussing and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    >>If I type in "shutdown /s /t 0" in a CMD window on that SBC, it does shut down.

    Based on your description, your case more related to single-board-computer (SBC) hardware environment, I would suggest you ask their manufacturer for better support. Thanks for your understanding.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 17, 2016 7:45 AM
    Moderator
  • No it is not about SBC or hardware. Please read my post. It is so short.
    Monday, October 17, 2016 7:59 AM
  • It could be related to your power and BIOS settings which can cause a restart after a shutdown. Here's one solution that someone found.

    It could also be caused by a BSOD that is being triggered at shutdown which will then trigger an automatic restart. There is an option in the UI to change that.  Looking in the event logs will help indicate a clearer picture.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Monday, October 17, 2016 2:34 PM
    Moderator
  • If possible, try invoking “shutdown” indirectly:

      var psi = new ProcessStartInfo( "cmd", "/C shutdown /s /t 0" );

      //psi.CreateNoWindow = true;

      psi.UseShellExecute = false;

      Process.Start( psi );

    Try with visible window first.

    • Marked as answer by Silan Liu Saturday, December 10, 2016 12:48 AM
    Monday, October 17, 2016 6:28 PM
  • Thanks for your help - I will try and let you know.
    Tuesday, October 18, 2016 3:59 AM
  • No it is not about SBC or hardware. Please read my post. It is so short.

    This is about the specific behavior of the shutdown command under specific circumstances. Not really a programming question, but a Windows one.

    As my only guess, I would say that the lack of an interactive session let's shutdown trip up somehow. Either it does not properly set the "actually halt when done" tag properly, or there is a BSOD case with automatic restart (as CoolDadTx said).


    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    • Marked as answer by Silan Liu Saturday, December 10, 2016 12:48 AM
    Tuesday, October 18, 2016 11:17 AM