private void UnLock() { LockWords = string.Empty; LockMinutes = string.Empty; App.Current.MainWindow.Topmost = false; MainWindow.Instance.Closing -= MainWindow_Closing; MainWindow.Instance.MainTextBox.TextChanged -= MainTextBox_TextChanged; //RWReg.RemoveKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableChangePassword"); //RWReg.RemoveKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableLockWorkstation"); //RWReg.RemoveKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr"); //RWReg.RemoveKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoLogoff"); IsUnlocked = true; if (null != _hook) { _hook.KeyMaskStop(); _hook = null; } MainWindow.Instance.ShowMessage("锁定功能已解除。"); }
internal void Lock() { // 软件尚未注册 if (!Verify()) { return; } var lockWords = Converter.ToInt(_lockWords); var lockMinutes = Converter.ToInt(_lockMinutes); if (lockWords > 0 || lockMinutes > 0) { _lockOriginLength = MainWindow.Instance.MainTextBox.Text.Length; _lockOriginTime = DateTime.Now; MainWindow.Instance.Closing -= MainWindow_Closing; MainWindow.Instance.Closing += MainWindow_Closing; IsUnlocked = false; if (SettingViewModel.Instance.IsViolenceLock) { #if !DEBUG App.Current.MainWindow.Topmost = true; #endif if (_hook == null) { _hook = new KeyboardHook(); _hook.KeyMaskStart(LockCallback); } //RWReg.SetValue(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableChangePassword", 1, true); //RWReg.SetValue(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableLockWorkstation", 1, true); //RWReg.SetValue(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 1, true); //RWReg.SetValue(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoLogoff", 1, true); } else if (SettingViewModel.Instance.IsTenderLock) { if (null != _hook) { _hook.KeyMaskStop(); _hook = null; } } if (lockMinutes > 0) { SurplusMinutes = lockMinutes; AutoUnlock(); } if (lockWords > 0) { SurplusWords = lockWords; MainWindow.Instance.MainTextBox.TextChanged -= MainTextBox_TextChanged; MainWindow.Instance.MainTextBox.TextChanged += MainTextBox_TextChanged; } if (lockMinutes > 0 && lockWords < 1) { MainWindow.Instance.ShowMessage("已启用锁定功能:锁定 {0} 分钟。", lockMinutes); } else if (lockWords > 0 && lockMinutes < 1) { MainWindow.Instance.ShowMessage("已启用锁定功能:锁定 {0} 字。", lockWords); } else { MainWindow.Instance.ShowMessage("已启用锁定功能:锁定 {0} 字和 {1} 分钟。", lockWords, lockMinutes); } } }