lock mouse and keybody:
using System.Runtime.InteropServices;
namespace sln_BlockInput
{
public partial class Form1 : Form
{
// API define
[DllImport("user32.dll")]
static extern void BlockInput(bool Block);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BlockInput(true); // lock
System.Threading.Thread.Sleep(10000); // wait for 10 second
BlockInput(false); // unlock
}
}
}
the code above can't lock Ctrl+Alt+del
Add the code below to lock Ctrl+Alt+Delete
using Microsoft.Win32;
private void TaskMgrCtrl(bool Locked)
{
int intValue=0;
if (Locked)
{ intValue = -1; }
else
{ intValue = 0; }
string key = @"software\microsoft\windows\currentversion\policies\";
Registry.CurrentUser.OpenSubKey(key + "system", true).SetValue("DisableTaskMgr", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoLogoff", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoClose", intValue);
Registry.CurrentUser.OpenSubKey(key + "system", true).SetValue("DisableLockWorkstation", intValue);
Registry.CurrentUser.OpenSubKey(key + "system", true).SetValue("DisableChangePassword", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoViewContextMenu", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoChangeStartMenu", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoRun", intValue);
Registry.CurrentUser.OpenSubKey(key + "Explorer", true).SetValue("NoSetTaskbar", intValue);
}
TaskMgrCtrl(true);//lock
// TaskMgrCtrl(false); // unlock