#region 屏蔽Windows功能键(快捷键)
public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
private static int hHook = 0;
public const int WH_KEYBOARD_LL = 13;
//LowLevel键盘截获,如果是WH_KEYBOARD=2,并不能对系统键盘截取,会在你截取之前获得键盘。
private static HookProc KeyBoardHookProcedure;
//键盘Hook结构函数
[StructLayout(LayoutKind.Sequential)]
public class KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
//设置钩子
[DllImport("user32.dll")]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
//抽掉钩子
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll")]
//调用下一个钩子
public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId();
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string name);
//如果函数执行成功,返回值不为0。
//如果函数执行失败,返回值为0。要得到扩展错误信息,调用GetLastError。
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(
IntPtr hWnd, //要定义热键的窗口的句柄
int id, //定义热键ID(不能与其它ID重复)
int fsModifiers, //标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效
Keys vk //定义热键的内容
);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool UnregisterHotKey(
IntPtr hWnd, //要取消热键的窗口的句柄
int id //要取消热键的ID
);
public static void Hook_Start()
{
// 安装键盘钩子
if (hHook == 0)
{
KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure,
GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
//如果设置钩子失败.
if (hHook == 0)
{
Hook_Clear();
}
}
}
//取消钩子事件
public static void Hook_Clear()
{
bool retKeyboard = true;
if (hHook != 0)
{
retKeyboard = UnhookWindowsHookEx(hHook);
hHook = 0;
}
//如果去掉钩子失败.
if (!retKeyboard) throw new Exception("Hook去除失败");
}
//这里可以添加自己想要的信息处理
private static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode >= 0)
{
KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
if (kbh.vkCode == 91) // 截获左win(开始菜单键)
{
return 1;
}
if (kbh.vkCode == 92)// 截获右win(开始菜单键)
{
return 1;
}
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control) //截获Ctrl+Esc
{
return 1;
}
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Alt) //截获Alt+Esc
{
return 1;
}
if (kbh.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+f4
{
return 1;
}
if (kbh.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+tab
{
return 1;
}
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift+Esc
{
return 1;
}
if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+空格
{
return 1;
}
if (kbh.vkCode == 241) //截获F1
{
return 1;
}
if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt + (int)Keys.Delete) //截获Ctrl+Alt+Delete
{
return 1;
}
if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift
{
return 1;
}
if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt) //截获Ctrl+Alt+空格
{
return 1;
}
if (kbh.vkCode == (int)Keys.LWin)
{
return 1;
}
if (kbh.vkCode == (int)Keys.RWin)
{
} return 1;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
/// <summary>
/// 开打任务管理器快捷键为Windows底层按键
/// </summary>
/// <param name="bLock"></param>
public static void TaskMgrLocking(bool bLock)
{
if (bLock)//屏蔽任务管理器、并且不出现windows提示信息“任务管理器已被管理员禁用”
{
Process p = new Process();
p.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);
p.StartInfo.FileName = "taskmgr.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
}
else//设置任务管理器为可启动状态
{
Process[] p = Process.GetProcesses();
foreach (Process p1 in p)
{
try
{
if (p1.ProcessName.ToLower().Trim() == "taskmgr")//这里判断是任务管理器
{
p1.Kill();
RegistryKey r = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
r.SetValue("DisableTaskmgr", "0"); //设置任务管理器为可启动状态
Registry.CurrentUser.DeleteSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
}
}
catch
{
return;
}
}
}
}
#endregion
//调用
private void button1_Click(object sender, EventArgs e)
{
//启动钩子,处理钩子事件
Hook_Start();
//屏蔽任务管理器
TaskMgrLocking(true);
}
/// <summary>
/// 关闭窗口时事件
/// </summary>
//private void Form1_FormClosing(object sender, FormClosingEventArgs e)
//{ //注销Id号为100的热键设定
// UnregisterHotKey(Handle, 100); //注销Id号为101的热键设定
// UnregisterHotKey(Handle, 101); //注销Id号为102的热键设定
// UnregisterHotKey(Handle, 102); //注销Id号为103的热键设定
// UnregisterHotKey(Handle, 103);
// Hook_Clear();
// TaskMgrLocking(false);
// }
- C# 屏蔽Ctrl Alt Del 快捷键方法+屏蔽所有输入
原文:C# 屏蔽Ctrl Alt Del 快捷键方法+屏蔽所有输入 Win32.cs /* * * FileCreate By Bluefire * Used To Import WindowsApi ...
- {Django基础十之Form和ModelForm组件}一 Form介绍 二 Form常用字段和插件 三 From所有内置字段 四 字段校验 五 Hook钩子方法 六 进阶补充 七 ModelForm
Django基础十之Form和ModelForm组件 本节目录 一 Form介绍 二 Form常用字段和插件 三 From所有内置字段 四 字段校验 五 Hook钩子方法 六 进阶补充 七 Model ...
- idea快捷键:查找类中所有方法的快捷键
查找类中所有方法的快捷键 第一种:ctal+f12,如下图 第二种:alt+7,如下图
- Android进程so注入Hook java方法
本文博客链接:http://blog.csdn.net/qq1084283172/article/details/53769331 Andorid的Hook方式比较多,现在来学习下,基于Android ...
- idea 查看 类所有方法的快捷键
idea 查看 类 所有方法的快捷键 Idea:ctrl+F12 Eclipse:Ctrl+O
- 【Eclipse】_Eclipse自动补全增强方法 & 常用快捷键
一,Eclipse自动补全增强方法 在Eclipse中,从Window -> preferences -> Java -> Editor -> Content assist - ...
- Eclipse自动生成方法注释 快捷键
自动生成方法的注释格式,例如 /*** @param str* @return* @throws ParseException*/ 快捷键是 ALT + SHIFT + J,将光标放在方法名上,按快捷 ...
- c# 屏蔽快捷键
前言 有时候开发会遇到这样一个需求,软件需要屏蔽用户的组合快捷键或某些按键,避免强制退出软件,防止勿操作等. 原理 1.要实现组合键,按键拦截,需要用到user32.dll中的SetWindowsHo ...
- 【转】微软教学:三种方法屏蔽Win7/Win8.1升级Win10推送
原文地址:http://www.ithome.com/html/win10/199961.htm 微软在2015年6月就开启了Win10升级推送工作,主要是靠<获取Windows10>工具 ...
随机推荐
- Codeforces834D - The Bakery
Portal Description 给出一个\(n(n\leq35000)\)个数的数列\(\{a_i\}\)和\(m(m\leq50)\).将原数列划分成\(m\)个连续的部分,每个部分的权值等于 ...
- AC日记——最大子树和 洛谷 P1122
题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...
- CSS-实现倒影效果box-reflect
我需要的效果: html: <img src="images/my1.jpg" width="20%"/> css: img{-webkit-b ...
- html --- rem
// rem (function(doc, win) { var docEle = doc.documentElement, evt = "onorientati ...
- js拖拽效果的实现
1.最基础的写法 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> < ...
- L1-5. A除以B【一种输出格式错了,务必看清楚输入输出】
L1-5. A除以B 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 真的是简单题哈 —— 给定两个绝对值不超过100的整数A和 ...
- django使用logging记录日志
django使用logging记录日志,我没有用这方式去记录日志,主要还是项目小的原因吧, 有机会遇见大项目的话可以回头研究. 配置setting.py配置文件 import logging impo ...
- luogu P1140 相似基因
题目背景 大家都知道,基因可以看作一个碱基对序列.它包含了4种核苷酸,简记作A,C,G,T.生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物. 在一个人类基因工作组的任务中,生物学家研究 ...
- ArrayList和LinkedList学习
摘要 ArrayList和LinkedList是对List接口的不同数据结构的实现.它们都是线程不安全的,线程不安全往往出现在数组的扩容.数据添加的时候. 一.ArrayList和LinkedList ...
- JRoll 2 使用文档(史上最强大的下拉刷新,滚动,无限加载插件)
概述 说明 JRoll,一款能滚起上万条数据,具有滑动加速.回弹.缩放.滚动条.滑动事件等功能,兼容CommonJS/AMD/CMD模块规范,开源,免费的轻量级html5滚动插件. JRoll第二版是 ...