How to shutdown a computer programmatically in Windows
If you are writing some installer application, want to update system files, apply settings of for some other reason, you may need to shutdown (reboot, power off) a Windows 10 computer. The good news is that Windows has a pretty straightforward API for this intent, which is called ExitWindowsEx. It has only two parameters. The first one is the flags parameter which you can set to either reboot or power-off and the second one - the reboot reason, which is only used on servers and is not mandatory. But the bad news is that the functions won't work as-is. In order to make it work, you need to enable the shutdown privilege, which is disabled by default. I advise you to enable this privilege only directly before you decide to shut down.
