一:截图,主要是调用系统接口和更改注册表实现功能
二:代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.Win32; namespace 关机一键锁定 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } #region 隐藏、显示任务栏 [DllImport("user32.dll")] public static extern IntPtr FindWindow(String className, String captionName); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hwnd, uint nCmdShow); //隐藏光标 [DllImport("user32.dll", EntryPoint = "ShowCursor")] public static extern bool ShowCursor(bool bShow); //ShowCursor(false); private void btnHideToolBar_Click(object sender, RoutedEventArgs e) { // 获得任务栏和开始菜单的句柄 var rwl = FindWindow("Shell_TrayWnd", null); var rwl2 = FindWindow("Button", null); if (btnHideToolBar.Content == "隐藏")//当nCmdShow=0---隐藏;nCmdShow=1---显示 { ShowWindow(rwl2,1 ); ShowWindow(rwl, 1); ShowCursor(true); btnHideToolBar.Content = "显示"; } else { ShowWindow(rwl2, 0); ShowWindow(rwl, 0); ShowCursor(false); btnHideToolBar.Content = "隐藏"; } } #endregion //禁用、启用任务管理器 private void btnManageForm_Click(object sender, RoutedEventArgs e) { if (btnManageForm.Content == "禁用")//当nCmdShow=0---隐藏;nCmdShow=1---显示 { //禁用本机的任务管理器 Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 1); //禁用当前用户任务管理器 Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 1); btnManageForm.Content = "启用"; } else { //禁用本机的任务管理器 Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 0); //禁用当前用户任务管理器 Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 0); btnManageForm.Content = "禁用"; } } } }
三:后记
如果这些代码将任务栏和开始菜单隐藏掉,仅想通过界面鼠标操作恢复还是有点难度的,希望用的朋友不要擅自用于别人电脑。