'How to automatically power off the computer by calling the Win32 API function in C#

I'm trying to schedule a shutdown of my computer on C# by calling the following API function but when I call this function nothing happens. Can anyone help me fix it.

[DllImport("advapi32.dll", SetLastError = true)]
static extern UInt32 InitiateShutdownA(string lpMachineName, string lpMessage, UInt32 dwGracePeriod, UInt32 dwShutdownFlags, UInt32 dwReason);

internal const int EWX_POWEROFF = 0x00000008;
InitiateShutdownA(System.Environment.MachineName, "SHUTDOWN", 10, EWX_POWEROFF, 0);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source