Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the <code>ExitWindowsEx</code> API via pinvoke.net.</p> <p>See the <a href="http://pinvoke.net/default.aspx/user32/ExitWindowsEx.html" rel="nofollow noreferrer">ExitWindowsEx</a>, <a href="http://www.pinvoke.net/default.aspx/Enums/ExitWindows.html" rel="nofollow noreferrer">ExitWindows-Enum</a> and <a href="http://www.pinvoke.net/default.aspx/Enums/ShutdownReason.html" rel="nofollow noreferrer">ShutdownReason-Enum</a> on pinvoke.net for more information. Note that your process must have the <code>SE_SHUTDOWN_NAME</code> priviledge aquired (for example via <a href="http://www.pinvoke.net/default.aspx/advapi32/AdjustTokenPrivileges.html" rel="nofollow noreferrer">AdjustTokenPrivileges</a> API).</p> <p>The answers to <a href="https://stackoverflow.com/questions/102567/how-to-shutdown-the-computer-from-c">this stackoverflow question</a> contain some "complete" examples (although most of them are missing errorchecking and resource cleanup - the latter might not matter when you successfully shutdown, YMMV).</p> <p>Finally, note that using <code>Process.Start()</code> as you showed, without a fully qualified name to <code>shutdown.exe</code> is also problematic from a security standpoint. Someone could put a malicious EXE named shutdown in your PATH. Since you probably need to run with admin rights to be able to execute the "real" shutdown.exe, this can cause some trouble. If you specify something like <code>Process.Start(Environment.ExpandEnvironmentVariables("%windir%\system32\shutdown.exe"))</code> you can at least assume that the real shutdown.exe is protected from malicious replacement by file system rights (if the attacker himself is an admin your basically busted anyway).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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