Wednesday, March 13, 2013

Lock, Stand By, Hibernate and Log Off your System

using System.Runtime.InteropServices;

//Locking the system
[DllImport("user32.dll")]
public static extern void LockWorkStation();


LockWorkStation();
Application.SetSuspendState(PowerState.Suspend, true, true);

//Making system stand by and hibernation

Application.SetSuspendState(PowerState.Suspend, true, true);
Application.SetSuspendState(PowerState.Hibernate, true, true);

//Log off the user

[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReason);

ExitWindowsEx(0, 0);

No comments:

Post a Comment