System Shutdown from WinForm App

  • Thread starter Thread starter Royce
  • Start date Start date
R

Royce

Hi,

Can someone tell me how to send a System Shutdown message
from a WinForm application?

TIA,
Royce
 
If you mean to shutdown the local machine or Remote machine, have a look at the WMI interfaces in the system.management classes.
 
Hi, Royce

You have to use ExitWindowsEx API and here is example, which I use with
EWX_SHUTDOWN

[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flag, int reason );

public const int EWX_LOGOFF = 0x00000000;
public const int EWX_SHUTDOWN = 0x00000001;
public const int EWX_REBOOT = 0x00000002;
public const int EWX_FORCE = 0x00000004;
public const int EWX_POWEROFF = 0x00000008;
public const int EWX_FORCEIFHUNG = 0x00000010;

{
flg=EWX_SHUTDOWN;
ExitWindowsEx( flg, 0 );
}

HTH
Alex
 
Back
Top