[DllImport("user32.dll")] public static extern int ExitFunc(int operationFlag, int operationReason);
Vypnúť windows
ExitFunc(1, 0);
Reštartovať windows
ExitFunc(2, 0);
Odhlásiť windows
ExitFunc(0, 0);
Kód v c#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ShutDown { public partial class Form1 : Form { [DllImport("user32.dll")] public static extern int ExitFunc(int operationFlag, int operationReason); public Form1() { InitializeComponent(); } protected void btnRestart_Click(object sender, EventArgs e) { ExitFunc(2, 0); } protected void btnLogOff_Click(object sender, EventArgs e) { ExitFunc(0, 0); } protected void btnShutDown_Click(object sender, EventArgs e) { ExitFunc(1, 0); } } }
Použitím príkazového riadku
System.Diagnostics.Process.Start("shutdown", "/s");
Parametre :
- /l logoff - odhlásiť
- /s shuts down - vypnúť windows
- /r restarts - reštartovať windows
- /h hibernates windows