Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A quick inspection of shutdown.exe's usage message reveals that it expects option arguments following slashes ('/') not dashes ('-').</p> <p>Replacing the line:</p> <pre><code> startInfo.Arguments = "–s –f –t " + seconds; </code></pre> <p>With:</p> <pre><code> startInfo.Arguments = "/s /f /t " + seconds; </code></pre> <p>Yields a working result on my box with C# express 2010.</p> <p>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.</p> <pre><code> startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; Process p = Process.Start(startInfo); string outstring = p.StandardOutput.ReadToEnd(); string errstring = p.StandardError.ReadToEnd(); p.WaitForExit(); </code></pre> <p>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.</p> <p>The full listing of code below:</p> <pre><code> 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(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload