turn power on/off

  • Thread starter Thread starter cfyam
  • Start date Start date
Try this:

//
// Required O.S. function declaration
//
[DllImport("coredll.dll")]
public static extern void keybd_event(byte bVK, byte bScan, int
dwFlags, int dwExtraInfo);

//
// Hardware key constants and functions
//
public const int KEYEVENTF_KEYDOWN = 0x0;
public const int KEYEVENTF_KEYPRESS = 0x1;
public const int KEYEVENTF_KEYUP = 0x2;
public const int KEYEVENTF_SILENT = 0x4;
public const int VK_OFF = 0xDF;

//
// Call this function from your button
//
public static void PowerOffSystem()
{
keybd_event(VK_OFF, 0, KEYEVENTF_KEYDOWN, 0); // Press the power
button
keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0); // Release the power
button
}
 
Back
Top