Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
MrakDev committed Feb 13, 2020
1 parent 8a18b89 commit 0806844
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# TaskManager-Button-Disabler
Simple way to disable/rename buttons from a task manager

![APM](https://img.shields.io/apm/l/vim-mode?style=for-the-badge)

Simple way to disable/rename buttons from a task manager.


### Installation
```PS
git clone https://github.com/Mrakovic-ORG/TaskManager-Button-Disabler
cd TaskManager-Button-Disabler\TaskManager-Button-Disabler
dotnet build
```

### Features

- Rename kill proccess button
- Disable kill proccess button
- Works in TaskMgr and ProcessHacker


Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions TaskManager Button Disabler/TaskManager Button Disabler.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskManager Button Disabler", "TaskManager Button Disabler\TaskManager Button Disabler.csproj", "{7628913F-976B-4859-9F18-9EBAEEC926C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace TaskManager_Button_Disabler
{
public static class NativeApi
{
[DllImport("user32.dll")]
public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);

[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, ref int lpdwProcessId);

[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", CharSet = CharSet.Ansi, EntryPoint = "GetClassNameA", ExactSpelling = true, SetLastError = true)]
public static extern int GetClassName(int hwnd, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpClassName, int nMaxCount);

[DllImport("user32.dll", CharSet = CharSet.Ansi, EntryPoint = "SendMessageA", ExactSpelling = true, SetLastError = true)]
public static extern int SendMessage(int hwnd, int vMsg, int wParam, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowText(int hwnd, StringBuilder lpString, int cch);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GetWindowTextLength(int hwnd);

[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern int EnumChildWindows(IntPtr hWnd, EnumWindProc lpEnumFunc, ref int lParam);

public delegate bool EnumWindProc(int hWnd, int lParam);
public delegate bool EnumChildWindProc(int hWnd, int lParam);
}
}
46 changes: 46 additions & 0 deletions TaskManager Button Disabler/TaskManager Button Disabler/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;

namespace TaskManager_Button_Disabler
{
internal static class Program
{
private static bool _started = false;
private static readonly TBD Disabler = new TBD();

public static void Main()
{
go_back:
Console.Clear();

var status = _started ? "Stop" : "Start";
Console.WriteLine($"Keypress Enter to {status}.");

var check = Console.ReadKey();
switch (check.Key)
{
case ConsoleKey.Enter:
Enter();
break;
default:
Environment.Exit(0);
break;
}

goto go_back;
}

private static void Enter()
{
if (_started)
{
Disabler.Stop();
_started = false;
}
else
{
Disabler.Start();
_started = true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TaskManager_Button_Disabler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mrakovic ORG")]
[assembly: AssemblyProduct("TaskManager_Button_Disabler")]
[assembly: AssemblyCopyright("Copyright © Mrakovic 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7628913F-976B-4859-9F18-9EBAEEC926C1")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
160 changes: 160 additions & 0 deletions TaskManager Button Disabler/TaskManager Button Disabler/TBD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;

namespace TaskManager_Button_Disabler
{
public class TBD
{
#region "Config"

readonly string[] _processes = { "taskmgr", "processhacker", "proccess explorer" };
static string _newMsg = "NO BOII";

#endregion

enum _threadStatus
{
Run = 0,
Stop = 1,
};

_threadStatus atualStatus = _threadStatus.Stop;

List<IntPtr> _cld = new List<IntPtr>();

public TBD()
{
new Thread(DFunction) { IsBackground = true }.Start();
}

/// <summary>
/// Start button disabler
/// </summary>
public void Start()
{
atualStatus = _threadStatus.Run;
}

/// <summary>
/// Stop button disabler
/// </summary>
public void Stop()
{
atualStatus = _threadStatus.Stop;
}

void DFunction()
{
while (true)
{
//Wait on status to be true
while (atualStatus == _threadStatus.Run)
{
//Pause for few ms to avoid cpu consumption
Thread.Sleep(200);

//If actual window is not in foreground then continue
IntPtr hwd = NativeApi.GetForegroundWindow();
if (hwd.ToInt32() == 0)
continue;


var id = 0;
//Get process id by window handle (hwd)
NativeApi.GetWindowThreadProcessId(hwd, ref id);

//If process does not exist then continue
if (id <= 0) continue;

//Store process info from id into p
Process p = Process.GetProcessById(id);

//Check if ProcessName correspond to _processes
if (!_processes.Any(x => x == p.ProcessName.ToLower())) continue;
{

//Create a button list to store handles
List<IntPtr> button = new List<IntPtr>();
int statics = 0;

//Foreach handle(hwd) store to x
foreach (var x in GetChild(hwd))
{
//Get type of handle in className
string className = new string(' ', 200);
int ln = NativeApi.GetClassName((int)x, ref className, 200);
className = className.Remove(ln, 200 - ln);

switch (className.ToLower())
{
//If className(type) is button then add it to button list
case "button":
button.Add(x);
break;

//If className(type) is static or directuihwnd then increase number of statics var
case "static":
case "directuihwnd":
++statics;
break;
}
}

//If window does not have 2 buttons then continue
if (button.Count != 2)
continue;
//If window does not have between 0-2 class named static & directuihwnd then continue
else if (!(statics > 0 && statics < 3))
continue;

//Finally the funny part, disable button and change text to _newMsg
NativeApi.EnableWindow(button[0], false);
NativeApi.SendMessage((int)button[0], 12, 0, ref _newMsg);

//Watermark ma bruda 😋
string watermark = "by Mrakovic";
NativeApi.SendMessage((int)button[1], 12, 0, ref watermark);
}
}
}
}

/// <summary>
/// Get child windows of an process
/// </summary>
bool EnumChild(int hWnd, int lParam)
{
_cld.Add((IntPtr)hWnd);
return true;
}

IEnumerable<IntPtr> GetChild(IntPtr hwd)
{
bool flag = false;
IntPtr[] getChild;
try
{
Monitor.Enter(this, ref flag);
_cld.Clear();
NativeApi.EnumWindProc lpEnumFunc = EnumChild;
int num = 0;
NativeApi.EnumChildWindows(hwd, lpEnumFunc, ref num);
getChild = _cld.ToArray();
}
finally
{
var flag2 = flag;
if (flag2)
{
Monitor.Exit(this);
}
}

return getChild;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7628913F-976B-4859-9F18-9EBAEEC926C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TaskManager_Button_Disabler</RootNamespace>
<AssemblyName>TaskManager_Button_Disabler</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="NativeApi.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TBD.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.manifest" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 0806844

Please sign in to comment.