Archived
1
1
This repository has been archived on 2026-03-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RTUnlocker/MetroUnlocker/Rebooter.cs
Lasse Lauwerys f20cf222a8 Initial commit
2025-02-20 16:33:04 +01:00

34 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Runtime.InteropServices;
using System.Management;
namespace MetroUnlocker
{
public class Rebooter
{
public enum RebootMethod
{
LogOff = 0,
PowerOff = 8,
Reboot = 2,
ShutDown = 1,
Suspend = -1,
Hibernate = -2
}
public static void Reboot(RebootMethod method = RebootMethod.Reboot)
{
ManagementClass management = new ManagementClass("Win32_OperatingSystem");
management.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams = management.GetMethodParameters("Win32Shutdown");
mboShutdownParams["Flags"] = method;
mboShutdownParams["Reserved"] = 0;
management.GetInstances().OfType<ManagementObject>().First().InvokeMethod("Win32Shutdown", mboShutdownParams, null);
}
}
}