Articles

Navigation ( archives ›› 2006 ›› November ›› 20 ›› How to disable task manager in windows xp in csharp )

How to disable task manager in windows xp in csharp

Posted on November 20, 2006, 10:45 am EST

Disabling task manager in C# is very easy! Some people are wondering how to disable some sort of administrator privelges or specific windows actions from desktop. So I will supply some code that will secure your windows xp desktop.

Technically, this small class will allow you to lock the task manager and lock the control panel. Many stuff exist in the registry of windows, and by modifying some of them, you can disable those properties. In this example, I am showing how to disable 2 parts. And both exist in the registry...

CODE:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

///
/// Mohamed Mansour
/// http://www.m0interactive.com
/// 11/20/2006
/// 
/// LGPL Liscense
///
namespace Utility.Security
{
    /// <summary>
    /// Registry Item Object
    /// </summary>
    class RegItem
    {
        private String name;
        private String value;
        public RegItem (String name, String value)
        {
            this.name = name;
            this.value = value;
        }
        public String getName()
        {
            return name;
        }
        public String getValue()
        {
            return value;
        }
    }

    /// <summary>
    /// Heys
    /// </summary>
    public class WIN32Security
    {
        private RegItem[] RegValues = new RegItem[2];

        /// <summary>
        /// Constructor
        /// </summary>
        public WIN32Security()
        {
            RegValues[0] = new RegItem("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", "DisableTaskMgr");
            RegValues[1] = new RegItem("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoControlPanel");
        }

        /// <summary>
        /// Secure the System
        /// </summary>
        public void SetSecureSystem()
        {
            for (int i = 0; i < RegValues.Length; i++)
            {
                SetRegistryValue(RegValues[i].getName(), RegValues[i].getValue(), 1);
            }
        }

        /// <summary>
        /// Unsecure the System
        /// </summary>
        public void UnsetSecureSystem()
        {
            for (int i = 0; i < RegValues.Length; i++)
            {
                SetRegistryValue(RegValues[i].getName(), RegValues[i].getValue(), 0);
            }
        }

        /// <summary>
        /// Sets the Registry Values of the Sysyem
        /// </summary>
        /// <param name="name">The Path of the registry</param>
        /// <param name="value">Registry Name</param>
        /// <param name="newvalue">Registry Name Value</param>
        private void SetRegistryValue(String name, String value, object newvalue)
        {
            // Attempt to open the key "Software\\Play\\WindowPos"
            RegistryKey key = Registry.CurrentUser.CreateSubKey(name);
            key.SetValue(value, newvalue);
            Registry.CurrentUser.Flush();
        }
    }
}

Basically its only registry read and write. There are many other keys that could be inputed into the registry, I will update this blog after I make a table explaining them.

I hope that class would be sufficient for minimal applications.

About this Article:

Comments (1) - Add yours, or View the replies

Categoy (CSharp)

Views (4551)

Digg it: Digg this article