
2023年5月27日发(作者:夏天到了后面补充句子)
#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(tial)]
public class KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
//设置钩子
[DllImport("")]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("", CharSet = , CallingConvention = l)]
//抽掉钩子
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("")]
//调用下一个钩子
public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
[DllImport("")]
public static extern int GetCurrentThreadId();
[DllImport("")]
public static extern IntPtr GetModuleHandle(string name);
public static void Hook_Start()
{
// 安装键盘钩子
if (hHook == 0)
{
KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure,
GetModuleHandle(rentProcess().Name), 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)tructure(lParam, typeof(KeyBoardHookStruct));
if ( == 91) // 截获左win(开始菜单键)
{
return 1;
}
if ( == 92)// 截获右win(开始菜单键)
{
return 1
;
}
if ( == (int) && (int)erKeys == (int)l) //截获Ctrl+Esc
{
return 1;
}
if ( == (int) && (int)erKeys == (int)) //截获Alt+Esc
{
return 1;
}
if ( == (int)Keys.F4 && (int)erKeys == (int)) //截获alt+f4
{
return 1;
}
if ( == (int) && (int)erKeys == (int)) //截获alt+tab
{
return 1;
}
if ( == (int) && (int)erKeys == (int)l + (int)) //截获Ctrl+Shift+Esc
{
return 1;
}
if ( == (int) && (int)erKeys == (int)) //截获alt+空格
{
return 1;
}
if ( == 241) //截获F1
{
return 1;
}
if ((int)erKeys == (int)l + (int) + (int)) //截获Ctrl+Alt+Delete
{
return 1;
}
if ((int)erKeys == (int)l + (int)) //截获Ctrl+Shift
{
return 1;
}
if ( == (int) && (int)erKeys == (int)l + (int)) //截获Ctrl+Alt+空格
{
return 1;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
///
/// 开打任务管理器快捷键为Windows底层按键
/// ///
public static void TaskMgrLocking(bool bLock)
{
if (bLock)//屏蔽任务管理器、并且不出现windows提示信息“任务管理器已被管理员禁用”
{
Process p = new Process();
gDirectory = derPath();
me = "";
NoWindow = true;
Style = ;
();
}
el//设置任务管理器为可启动状态
{
Process[] p = cess();
foreach (Process p1 in p)
{
try
{
if (r().Trim() == "taskmgr")//这里判断是任务管理器
{
();
RegistryKey r = bKey("SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem", true);
ue("DisableTaskmgr", "0"); //设置任务管理器为可启动状态
SubKey("SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem");
}
}
catch
{
return;
}
}
}
}
#endregion
//调用
private void button1_Click(object nder, EventArgs e)
{
//启动钩子,处理钩子事件
Hook_Start();
//屏蔽任务管理器
TaskMgrLocking(true);
}
///
/// 关闭窗口时事件
/// private void Form1_FormClosing(object nder, 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(fal);
}