標籤:style blog http color os io ar for 2014
一:,主要是調用系統介面和更改註冊表實現功能
二:代碼
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 = "禁用"; } } }}三:後記
如果這些代碼將工作列和開始菜單隱藏掉,僅想通過介面滑鼠操作恢複還是有點難度的,希望用的朋友不要擅自用於別人電腦。
實戰基礎技能(13)--------C#代碼實現隱藏工作列、開始菜單和禁用工作管理員