Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:46:17+00:00 2026-05-28T06:46:17+00:00

I want to create a process which uses shutdown.exe to shut down the computer

  • 0

I want to create a process which uses shutdown.exe to shut down the computer after a given time.

Here is my code:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "–s –f –t " + seconds;
Process.Start(startInfo);

Where seconds is an int local variable, the user decides.

When i run my code nothing happens. But when i manually go in cmd prompt and type:
shutdown.exe – s -f -t 999
then Windows will make a popup and tell me that the system will shutdown in 16 mins.

The reason i think it’s because of the multiple arguments, is that my method to abort the ongoing system shutdown works(where i created the systemshutdown manually from cmd prompt). This is almost the same, except at startInfo.Argument:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "-a";
Process.Start(startInfo);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:46:18+00:00Added an answer on May 28, 2026 at 6:46 am

    A quick inspection of shutdown.exe’s usage message reveals that it expects option arguments following slashes (‘/’) not dashes (‘-‘).

    Replacing the line:

            startInfo.Arguments = "–s –f –t " + seconds;
    

    With:

            startInfo.Arguments = "/s /f /t " + seconds;
    

    Yields a working result on my box with C# express 2010.

    Also, you can redirect standard error and standard out of the started process to be read by your program, such that you can tell what happened after it ran. To do this, you can store the Process object and wait for the underlying process to exit so that you can check if everything went well.

            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
    
            Process p = Process.Start(startInfo);
            string outstring = p.StandardOutput.ReadToEnd();
            string errstring = p.StandardError.ReadToEnd();
            p.WaitForExit();
    

    Unfortunately, I can’t tell you why the command line version accepts ‘dash’ prefixes on the options and the C# executed version doesn’t. However, hopefully what you’re after is a working solution.

    The full listing of code below:

            int seconds = 100;
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = "shutdown.exe";
            startInfo.Arguments = "/s /f /t " + seconds;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            Process p = Process.Start(startInfo);
            string outstring = p.StandardOutput.ReadToEnd();
            string errstring = p.StandardError.ReadToEnd();
            p.WaitForExit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a program which can limit cpu usage of a process
I've written a C# application which uses System.Diagnostics.Process class to create a process, using
Here is the scenario: I have a java main process, which uses JMS to
i'm new at C Programming (i learned c++) i want to create a process
I want to produce a simple enough application which uses a QTreeView widget to
Given a Java Servlet (running on a Windows server) which creates a new process
I want to dynamically create multiple Process es, where each instance has a queue
I am trying to create a new process (which shouldn't block the current program)
I want to create a process B from process A . However, I don't
With win32api, I want that the following program creates two process and creates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.