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

Commit 0806844

Browse files
committed
Version 1.0
Initial release
1 parent 8a18b89 commit 0806844

11 files changed

Lines changed: 449 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
# TaskManager-Button-Disabler
2-
Simple way to disable/rename buttons from a task manager
2+
3+
![APM](https://img.shields.io/apm/l/vim-mode?style=for-the-badge)
4+
5+
Simple way to disable/rename buttons from a task manager.
6+
7+
8+
### Installation
9+
```PS
10+
git clone https://github.com/Mrakovic-ORG/TaskManager-Button-Disabler
11+
cd TaskManager-Button-Disabler\TaskManager-Button-Disabler
12+
dotnet build
13+
```
14+
15+
### Features
16+
17+
- Rename kill proccess button
18+
- Disable kill proccess button
19+
- Works in TaskMgr and ProcessHacker
20+
21+
Binary file not shown.

TaskManager Button Disabler/.vs/TaskManager Button Disabler/v16/Server/sqlite3/db.lock

Whitespace-only changes.
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskManager Button Disabler", "TaskManager Button Disabler\TaskManager Button Disabler.csproj", "{7628913F-976B-4859-9F18-9EBAEEC926C1}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{7628913F-976B-4859-9F18-9EBAEEC926C1}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Text;
4+
5+
namespace TaskManager_Button_Disabler
6+
{
7+
public static class NativeApi
8+
{
9+
[DllImport("user32.dll")]
10+
public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
11+
12+
[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
13+
public static extern int GetWindowThreadProcessId(IntPtr hwnd, ref int lpdwProcessId);
14+
15+
[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
16+
public static extern IntPtr GetForegroundWindow();
17+
18+
[DllImport("user32.dll", CharSet = CharSet.Ansi, EntryPoint = "GetClassNameA", ExactSpelling = true, SetLastError = true)]
19+
public static extern int GetClassName(int hwnd, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpClassName, int nMaxCount);
20+
21+
[DllImport("user32.dll", CharSet = CharSet.Ansi, EntryPoint = "SendMessageA", ExactSpelling = true, SetLastError = true)]
22+
public static extern int SendMessage(int hwnd, int vMsg, int wParam, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lParam);
23+
24+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
25+
public static extern int GetWindowText(int hwnd, StringBuilder lpString, int cch);
26+
27+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
28+
public static extern bool GetWindowTextLength(int hwnd);
29+
30+
[DllImport("user32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
31+
public static extern int EnumChildWindows(IntPtr hWnd, EnumWindProc lpEnumFunc, ref int lParam);
32+
33+
public delegate bool EnumWindProc(int hWnd, int lParam);
34+
public delegate bool EnumChildWindProc(int hWnd, int lParam);
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
3+
namespace TaskManager_Button_Disabler
4+
{
5+
internal static class Program
6+
{
7+
private static bool _started = false;
8+
private static readonly TBD Disabler = new TBD();
9+
10+
public static void Main()
11+
{
12+
go_back:
13+
Console.Clear();
14+
15+
var status = _started ? "Stop" : "Start";
16+
Console.WriteLine($"Keypress Enter to {status}.");
17+
18+
var check = Console.ReadKey();
19+
switch (check.Key)
20+
{
21+
case ConsoleKey.Enter:
22+
Enter();
23+
break;
24+
default:
25+
Environment.Exit(0);
26+
break;
27+
}
28+
29+
goto go_back;
30+
}
31+
32+
private static void Enter()
33+
{
34+
if (_started)
35+
{
36+
Disabler.Stop();
37+
_started = false;
38+
}
39+
else
40+
{
41+
Disabler.Start();
42+
_started = true;
43+
}
44+
}
45+
}
46+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("TaskManager_Button_Disabler")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("Mrakovic ORG")]
11+
[assembly: AssemblyProduct("TaskManager_Button_Disabler")]
12+
[assembly: AssemblyCopyright("Copyright © Mrakovic 2020")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("7628913F-976B-4859-9F18-9EBAEEC926C1")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
8+
namespace TaskManager_Button_Disabler
9+
{
10+
public class TBD
11+
{
12+
#region "Config"
13+
14+
readonly string[] _processes = { "taskmgr", "processhacker", "proccess explorer" };
15+
static string _newMsg = "NO BOII";
16+
17+
#endregion
18+
19+
enum _threadStatus
20+
{
21+
Run = 0,
22+
Stop = 1,
23+
};
24+
25+
_threadStatus atualStatus = _threadStatus.Stop;
26+
27+
List<IntPtr> _cld = new List<IntPtr>();
28+
29+
public TBD()
30+
{
31+
new Thread(DFunction) { IsBackground = true }.Start();
32+
}
33+
34+
/// <summary>
35+
/// Start button disabler
36+
/// </summary>
37+
public void Start()
38+
{
39+
atualStatus = _threadStatus.Run;
40+
}
41+
42+
/// <summary>
43+
/// Stop button disabler
44+
/// </summary>
45+
public void Stop()
46+
{
47+
atualStatus = _threadStatus.Stop;
48+
}
49+
50+
void DFunction()
51+
{
52+
while (true)
53+
{
54+
//Wait on status to be true
55+
while (atualStatus == _threadStatus.Run)
56+
{
57+
//Pause for few ms to avoid cpu consumption
58+
Thread.Sleep(200);
59+
60+
//If actual window is not in foreground then continue
61+
IntPtr hwd = NativeApi.GetForegroundWindow();
62+
if (hwd.ToInt32() == 0)
63+
continue;
64+
65+
66+
var id = 0;
67+
//Get process id by window handle (hwd)
68+
NativeApi.GetWindowThreadProcessId(hwd, ref id);
69+
70+
//If process does not exist then continue
71+
if (id <= 0) continue;
72+
73+
//Store process info from id into p
74+
Process p = Process.GetProcessById(id);
75+
76+
//Check if ProcessName correspond to _processes
77+
if (!_processes.Any(x => x == p.ProcessName.ToLower())) continue;
78+
{
79+
80+
//Create a button list to store handles
81+
List<IntPtr> button = new List<IntPtr>();
82+
int statics = 0;
83+
84+
//Foreach handle(hwd) store to x
85+
foreach (var x in GetChild(hwd))
86+
{
87+
//Get type of handle in className
88+
string className = new string(' ', 200);
89+
int ln = NativeApi.GetClassName((int)x, ref className, 200);
90+
className = className.Remove(ln, 200 - ln);
91+
92+
switch (className.ToLower())
93+
{
94+
//If className(type) is button then add it to button list
95+
case "button":
96+
button.Add(x);
97+
break;
98+
99+
//If className(type) is static or directuihwnd then increase number of statics var
100+
case "static":
101+
case "directuihwnd":
102+
++statics;
103+
break;
104+
}
105+
}
106+
107+
//If window does not have 2 buttons then continue
108+
if (button.Count != 2)
109+
continue;
110+
//If window does not have between 0-2 class named static & directuihwnd then continue
111+
else if (!(statics > 0 && statics < 3))
112+
continue;
113+
114+
//Finally the funny part, disable button and change text to _newMsg
115+
NativeApi.EnableWindow(button[0], false);
116+
NativeApi.SendMessage((int)button[0], 12, 0, ref _newMsg);
117+
118+
//Watermark ma bruda 😋
119+
string watermark = "by Mrakovic";
120+
NativeApi.SendMessage((int)button[1], 12, 0, ref watermark);
121+
}
122+
}
123+
}
124+
}
125+
126+
/// <summary>
127+
/// Get child windows of an process
128+
/// </summary>
129+
bool EnumChild(int hWnd, int lParam)
130+
{
131+
_cld.Add((IntPtr)hWnd);
132+
return true;
133+
}
134+
135+
IEnumerable<IntPtr> GetChild(IntPtr hwd)
136+
{
137+
bool flag = false;
138+
IntPtr[] getChild;
139+
try
140+
{
141+
Monitor.Enter(this, ref flag);
142+
_cld.Clear();
143+
NativeApi.EnumWindProc lpEnumFunc = EnumChild;
144+
int num = 0;
145+
NativeApi.EnumChildWindows(hwd, lpEnumFunc, ref num);
146+
getChild = _cld.ToArray();
147+
}
148+
finally
149+
{
150+
var flag2 = flag;
151+
if (flag2)
152+
{
153+
Monitor.Exit(this);
154+
}
155+
}
156+
157+
return getChild;
158+
}
159+
}
160+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{7628913F-976B-4859-9F18-9EBAEEC926C1}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TaskManager_Button_Disabler</RootNamespace>
11+
<AssemblyName>TaskManager_Button_Disabler</AssemblyName>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup>
35+
<ApplicationManifest>app.manifest</ApplicationManifest>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="NativeApi.cs" />
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
<Compile Include="TBD.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="app.manifest" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
54+
Other similar extension points exist, see Microsoft.Common.targets.
55+
<Target Name="BeforeBuild">
56+
</Target>
57+
<Target Name="AfterBuild">
58+
</Target>
59+
-->
60+
</Project>

0 commit comments

Comments
 (0)