實戰基礎技能(13)--------C#代碼實現隱藏工作列、開始菜單和禁用工作管理員

來源:互聯網
上載者:User

標籤: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#代碼實現隱藏工作列、開始菜單和禁用工作管理員

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.