日期:2014-05-18 浏览次数:20793 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Diagnostics; using System.IO; using System.Reflection; namespace LockScreen { public partial class frmLockScreen : Form { public frmLockScreen() { InitializeComponent(); } private string filePath=Application.StartupPath+@"\config.ini"; private string pwd; private int i=0; public string IniReadValue(string Section,string Key,string FilePath) { StringBuilder temp=new StringBuilder(255); int i=Win32API.GetPrivateProfileString(Section,Key,"",temp,255,FilePath); return temp.ToString(); } #region public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); HookProc KeyBoardProcedure; static int hHook=0; public const int WH_KEYBOARD=13; public struct KeyBoardHookStruct { public int vkCode; public int scanCode; public int flags; public int time; public int dwExtraInfo; } public void HookStart() { if(hHook==0) { KeyBoardProcedure=new HookProc(frmLockScreen.KeyBoardHookProc); hHook = Win32API.SetWindowsHookEx(WH_KEYBOARD, KeyBoardProcedure, Win32API.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); if(hHook==0) { HookClear(); } } } public void HookClear() { bool rsetKeyboard=true; if(hHook!=0) { rsetKeyboard=Win32API.UnhookWindowsHookEx(hHook); hHook=0; } if(!rsetKeyboard) { throw new Exception("取消钩子失败!"); } } public static int KeyBoardHookProc(int nCode,int wParam,IntPtr lParam) { if(nCode>=0) { KeyBoardHookStruct kbh=(KeyBoardHookStruct)Marshal.PtrToStructure(lParam,typeof(KeyBoardHookStruct)); if(kbh.vkCode==91) { return 1; } if(kbh.vkCode==92) { return 1; } if(kbh.vkCode==(int)Keys.Escape&&(int)Control.ModifierKeys==(int)Keys.Control) { return 1; } if(kbh.vkCode==(int)Keys.F4&&(int)Control.ModifierKeys==(int)Keys.Alt) { return 1; } if(kbh.vkCode==(int)Keys.Tab&&(int)Control.ModifierKeys==(int)Keys.Alt) { return 1; } } return Win32API.CallNextHookEx(hHook,nCode,wParam,lParam); } public static string MD5_Str(string PWD) { MD5 md5=MD5.Create(); byte[]s=md5.ComputeHash(Encoding.UTF8.GetBytes(PWD)); string password=""; for(int i=0;i<s.Length;i++) { password+=s[i].ToString(); } return password; } private void frmLockScreen_Load(object sender, EventArgs e) { HookStart(); pwd=IniReadValue("config","password",filePath); st