i want to restart my computer and have the script continue to run after

Darryl Weeks 21 Reputation points
2022-07-14T12:51:45.257+00:00

I want to make an application that runs scripts that automate basic troubleshooting steps. i want it to restart the computer first and foremost. after it reboots i want it to continue with the rest of the scripts. if you can explain to me how to make that happen i would appreciate it. i would prefer to use C# for this but at this point i will use anything that works.

Windows for business | Windows Client for IT Pros | Devices and deployment | Set up, install, or upgrade
Developer technologies | .NET | .NET CLI
Developer technologies | C#
{count} votes

Accepted answer
  1. satya karki 996 Reputation points MVP
    2022-07-14T15:33:32.773+00:00

    Hi,

    You may try the below code.

    var psi = new ProcessStartInfo("shutdown","/s /t 0");  
    psi.CreateNoWindow = true;  
    psi.UseShellExecute = false;  
    Process.Start(psi);  
    
    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rijwan Ansari 766 Reputation points MVP
    2022-07-14T15:29:04.23+00:00

    Hi @Darryl Weeks ,

    You can write below line of code to restart using C#.

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

    ------------------------------------------------------------------

    Please vote up and Accept as an Answer if my reply is helpful

    1 person found this answer helpful.
    0 comments No comments

  2. RLWA32 49,636 Reputation points
    2022-07-14T13:13:31.727+00:00

    Maybe you can use the RunOnce key to execute the rest of your scripts after a restart.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.