Disable Keyboard Shortcuts and Combination Keys with C# (2): Disable Win + L
来源:互联网 发布:睡觉流口水 知乎 编辑:程序博客网 时间:2024/06/01 08:49
The function of Win + L combination keys is to lock the computer or to switch users on Windows platform. The method introduced in the previous blog article can disable Win key, but cannot disable Win + L shortcut. So we must look for other ways. There is a DWORD (32-bit) value named by 'DisableLockWorkstation' in Windows registry. Its location is under the key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System
If there does not exist such a value, you can create it manually. To set the value as 0 will enable Win + L, to set the value as 1 will disable the combination. It's difficult and danger to require common users to modify Windows registry. To develop a specialized program is better. A C# program is given here. When it is run, the interface is as follows:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System
If there does not exist such a value, you can create it manually. To set the value as 0 will enable Win + L, to set the value as 1 will disable the combination. It's difficult and danger to require common users to modify Windows registry. To develop a specialized program is better. A C# program is given here. When it is run, the interface is as follows:
Step:
1. Create a C# Windows Forms application in Visual Studio. The project name is 'EnableOrDisableWinAndL';
2. Switch from code view to designer view, drag a label into the Windows Form from the toolbox. The label text is 'Enable or Disable Win + L ?'.
3. Drag three buttons into the Windows Form from the toolbox, named them by EnableButton, DisableButton and ExitButton;
4. Modify the file 'Form1.cs', the source code is as listed below:
/*************************************************** Author: HAN Wei* Author's blog: http://blog.csdn.net/henter/* Date: Dec. 5th, 2016* Description: demonstrate how to disable Win + L combination keys**************************************************/using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.Win32;namespace EnableOrDisableWinAndL{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } void SetRegistryValue(int value) { const string keyName = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; try { Registry.SetValue(keyName, "DisableLockWorkstation", value, RegistryValueKind.DWord); } catch (Exception e) { MessageBox.Show(e.Message); } } private void EnableButton_Click(object sender, EventArgs e) { SetRegistryValue(0); } private void DisableButton_Click(object sender, EventArgs e) { SetRegistryValue(1); } private void ExitButton_Click(object sender, EventArgs e) { Application.Exit(); } }}
5. Build the program, run it with Administrator Privileges. It is unnecessary to restart the computer.
0 0
- Disable Keyboard Shortcuts and Combination Keys with C# (2): Disable Win + L
- Disable Keyboard Shortcuts and Combination Keys with C# (1): Disable frequently used hotkeys
- Disable Keyboard Shortcuts and Combination Keys with C# (3): Disable Ctrl + Alt + Del
- mysql DISABLE/ENABLE KEYS
- disable thinkpad keyboard NmLk
- keyboard disable search key
- Disable Fireware and SELinux
- MySQL DISABLE/ENABLE KEYS的作用
- mysql中的/*! ... */ 注释和disable/enable keys
- Firefox Keyboard and Mouse Shortcuts
- Group Policy and disable autorun
- 650. 2 Keys Keyboard
- 650. 2 Keys Keyboard
- 650. 2 Keys Keyboard
- 650. 2 Keys Keyboard
- 650. 2 Keys Keyboard
- 650. 2 Keys Keyboard
- LeetCode-2 Keys Keyboard
- OpenGL API 之 glTexEnv
- Qt download
- 关于wsdl生成客户端代码中的JAXBElement<String>
- 生活服务类型-项目知识点总结
- Django快速开发web前端
- Disable Keyboard Shortcuts and Combination Keys with C# (2): Disable Win + L
- 面向对象思想概述
- 今天第一天写博客,随写
- 远程DNS缓存攻击__山东大学网络攻防实验三
- NFS /etc/exports 設定檔的語法與參數
- maven私服nexus配置
- uboot分析一
- VMware下基于RHEL_6.0虚拟机的samba服务器安装
- java实现获取鼠标在屏幕上的坐标