In order to turn off the computer using C#, you can use the built-in Process
class to execute the appropriate system command. Here's an example code snippet:
main.cs73 chars6 lines
The /s
flag tells the shutdown command to turn off the computer. The /t 0
flag specifies the delay in seconds before shutting down (in this case, 0 seconds, meaning immediate shut down.)
Note that this code requires administrative privileges to execute.
gistlibby LogSnag