Power off PC function?

enum class ShutdownAction
{
	NoReboot,
	Reboot,
	PowerOff
};
typedef NTSTATUS(__stdcall *NtShutdownSystem)(ShutdownAction shutdownAction);

I’m using “NtShutdownSystem(ShutdownAction::PowerOff);” to power off but this requires 2~3 seconds (slow).
I know a fast function for reset.
KeBugCheck(POWER_FAILURE_SIMULATE);
Is there a fast power off function like KeBugCheck()?

No

You do realize what the system is doing in those seconds it takes to shutdown right?

it is not as though the guys at Microsoft said, someone wants to shutdown the system, but we want to make that deliberately slow by calculating the first million digits of pi before we get started. during this time, which can extend into minutes depending on your hardware and OS config, the OS is carefully stopping critical components. ensuring that they stop cleanly so that they can presumably start cleanly. This includes things like flushing the file system cache to ensure that data is not lost and while the structure of modern file systems makes them inherently resilient against corruption caused by ‘pulling the power cord’, it does not follow that they are resilient against data loss under that scenario nor that is a desirable way to reset a system.

you should also note that depending on system config, rebooting via bug check can be significantly slower. Consider a system configured to write a full memory dump on failure with multiple TB of memory. Perhaps KeBugCheck(POWER_FAILURE_SIMULATE) bypasses this but I wouldn’t rely on it.

Actually we are developing diskless system and after the client reset or power off all data is cleared so data loss is not a problem. Yes I know what is done in 2~3 seconds including cache flushing but I think the clean-up or shutdown jobs are not needed and meaningless on diskless system. I just want to gain the faster power off speed… P.S: iSCSI diskless does not boot unless turn off kernel crash dump option so we turned off. KeBugCheck() will not create memory dump file. I still don’t know why always “ndis_dump.sys” crashes while iSCSI booting…

Well then you already have the answer: KeBugCheck(POWER_FAILURE_SIMULATE), with don’t generate dump file, shutdown rather than reboot.

KeBugCheck(POWER_FAILURE_SIMULATE) does not shutdown but reboot…

well, I have never known Windows to boot from ROM, so even if the disk is not installed in the chassis, iSCSI boot systems still have disks. The activities during shutdown are designed to make sure that that disk, along with any others that might exists, don’t lose data or get corrupted as they might be during an abortive reset. iSCSI is no more immune to this kind of corruption than any other kind of drive except for a ROM - since by definition it is read only.

if by diskless, you mean that it is a situation where after shutdown, your disk will be reverted to a previous known good state such as a VM snapshot, that is a different matter. But the result is still the same - if you want Windows to shutdown, it will do so cleanly. If you don’t care about that, then you have to do it at a level below Windows. A hypervisor can kill a VM, a management module can kill a physical server and a smart PDU can reset just about anything.

you have to do it at a level below Windows.

Thank you!