-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (44 loc) · 2.16 KB
/
Program.cs
File metadata and controls
48 lines (44 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.ComponentModel;
using System.Diagnostics;
namespace dnkill {
class Program {
private static bool debug = false;
static void Main (string[] args) {
if (args.Length >= 2) {
string targetProcName = args[0];
string excludeTag = args[1];
if (args.Length == 3 && args[2].Equals ("debug")) {
debug = true;
}
Process[] localByName = Process.GetProcessesByName (targetProcName);
foreach (Process proc in localByName) {
bool kill = true;
log ($"Id: {proc.Id} Title: {proc.MainWindowTitle} Process Name: {proc.ProcessName} {proc.MainModule.FileName} {proc.Modules.Count}");
ProcessModuleCollection procModuleCollection = proc.Modules;
for (int i = 0; i < procModuleCollection.Count; i++) {
ProcessModule procModule = procModuleCollection[i];
log ($"-The moduleName is {procModule.ModuleName} {procModule.FileName}");
if (procModule.ModuleName.Contains (excludeTag) || procModule.FileName.Contains (excludeTag)) {
kill = false;
log ($"-Excluding because is using module {procModule.ModuleName} at {procModule.FileName}");
}
}
if (kill) {
log ($"Killing Id: {proc.Id} Title: {proc.MainWindowTitle} Process Name: {proc.ProcessName}");
proc.Kill();
} else {
log ($"NOT Killing Id: {proc.Id} Title: {proc.MainWindowTitle} Process Name: {proc.ProcessName}");
}
}
} else {
Console.Out.WriteLine ("Please supply two arguments, the first is the process to find, and the second the keywords to exclude");
}
}
private static void log (string msg) {
if (debug) {
Console.Out.WriteLine (msg);
}
}
}
}