码迷,mamicode.com
首页 > 其他好文 > 详细

实战基础技能(13)--------C#代码实现隐藏任务栏、开始菜单和禁用任务管理器

时间:2014-08-29 17:43:58      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   for   2014   

一:截图,主要是调用系统接口和更改注册表实现功能

bubuko.com,布布扣

二:代码

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#代码实现隐藏任务栏、开始菜单和禁用任务管理器

标签:style   blog   http   color   os   io   ar   for   2014   

原文地址:http://www.cnblogs.com/hongmaju/p/3945282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!