static bool pressAnyKeyToStart() { // returns true if 'debug mode' is desired. bool bEnableDebugMode = false; PrintMsg: Console.WriteLine("WARNING: ANY DATA NOT SAVED WILL BE LOST! (Close this window to abort.)\n"); if (Console.WindowWidth < 120) { Console.WriteLine("Press 'C' for KillEmAll.NET Configuration"); Console.WriteLine("Press 'D' to run KillEmAll.NET (in Debug Mode)"); } else { Console.WriteLine("Press 'D' to run KillEmAll.NET (in Debug Mode) Press 'C' for KillEmAll.NET Configuration"); } if (!isRunningAsAdmin()) { Console.WriteLine("Press 'A' to run KillEmAll.NET (as Administrator)"); } Console.Write("\nPress any other key to start. . ."); GetInput: ConsoleKeyInfo foo = Console.ReadKey(); switch (foo.Key) { case ConsoleKey.A: if (isRunningAsAdmin()) { goto GetInput; } // if function returns true, be sure to end execution of this instance since we're relaunching as admin if (launchSelfAsAdministrator()) { Environment.Exit(0); } break; case ConsoleKey.C: System.Windows.Forms.Form config = new ConfigUI(); config.ShowDialog(); goto GetInput; case ConsoleKey.D: bEnableDebugMode = true; break; case ConsoleKey.I: Console.Clear(); Console.WriteLine("\nConfig File = " + _iniFile); Console.WriteLine("Log File = " + getLogFilePathAndName()); Console.WriteLine(""); goto PrintMsg; } // always clear console after prompt Console.Clear(); return(bEnableDebugMode); }
void killProcess(int PID, string processName, string fullPath = "") { bool bSuccess = false; bool bKill = false; string sResult = ""; // use full path (only if we have one) for initial user display and log text, else use process name only. string sSubject = processName; if (fullPath.Contains("\\")) { sSubject = fullPath; } // only if not flagged to skip everything if (!_skipAllAfterTerminatingDebugMode) { // only if we haven't skipped this process already if (!_skippedProcesses.ContainsKey(sSubject)) { // check to see if we've already terminated this process if (_terminatedProcesses.ContainsKey(sSubject)) { // flag to kill and skip the rest bKill = true; } else { // only if in debug mode if (_debugMode) { // use to prevent user from filling the screen with duplicate file info, so we don't have to rewrite the terminate prompt for clarity bool bAlreadyPrintedFileInfo = false; PrintMsg: Console.WriteLine(""); Console.Write($"Terminate process: \"{sSubject}\" [Y/n] (Yes/No)?"); // if configured to always show info if (_debugModeShowInfo) { // even though we test for this in the printFileInfo() method, when tested there it prints an error, // but here when this setting is enabled automatically, it shouldn't print that error, so don't even call the method... if (fullPath.Contains("\\")) { // flag true to ensure file info is printed only once bAlreadyPrintedFileInfo = true; printFileInfo(fullPath, processName); } } GetUserInput: // moved from before GetUserInput: because we may change settings mid-program now and this variable needs to be reinterpreted. // determine search string based on config setting; default to processName when setting does not exist string searchString = ""; if (_searchFileNameOnly) { searchString = processName; } else { searchString = sSubject; } // read key ConsoleKeyInfo foo = Console.ReadKey(); Console.WriteLine(""); switch (foo.Key) { case ConsoleKey.Q: Console.Write("\nTerminate all remaining processes? [Y/n] (Yes/No)"); bool terminateAll = false; QuitPrompt: ConsoleKeyInfo bar = Console.ReadKey(); switch (bar.Key) { case ConsoleKey.Enter: terminateAll = true; break; case ConsoleKey.Y: terminateAll = true; break; case ConsoleKey.N: break; case ConsoleKey.Escape: break; default: goto QuitPrompt; } if (terminateAll) { Console.WriteLine("\nQuitting Debug Mode (Terminating all remaining processes). . .\n"); // ensure we kill the currently selected process bKill = true; } else { Console.WriteLine("\nQuitting Debug Mode (Skipping all remaining processes). . .\n"); // ensure we skip all remaining processes _skipAllAfterTerminatingDebugMode = true; } // disable Debug mode for future loops _debugMode = false; break; case ConsoleKey.C: System.Windows.Forms.Form config = new ConfigUI(); config.ShowDialog(); // get potential settings changes from INI getSettingsFromINI(); goto GetUserInput; case ConsoleKey.G: webSearch(searchString); goto GetUserInput; case ConsoleKey.W: webSearch(searchString); goto GetUserInput; case ConsoleKey.S: webSearch(searchString); goto GetUserInput; case ConsoleKey.I: if (!bAlreadyPrintedFileInfo) { // flag true to ensure file info is printed only once bAlreadyPrintedFileInfo = true; printFileInfo(fullPath, processName); } goto GetUserInput; case ConsoleKey.O: openInExplorer(fullPath); goto GetUserInput; case ConsoleKey.P: openInCommandPrompt(fullPath); goto GetUserInput; case ConsoleKey.H: Console.Clear(); Console.WriteLine(""); if (_file_d7xEXE.Length > 0) { Program.PrintDebugHelp(true); } else { Program.PrintDebugHelp(false); } // in case user wants to see that info again if (!_debugModeShowInfo) { bAlreadyPrintedFileInfo = false; } goto PrintMsg; case ConsoleKey.E: if (_file_d7xEXE.Length > 0) { if (fullPath.Contains("\\")) { launchd7x("/et=" + fullPath); } else { Console.WriteLine("\n [No file path; cannot send file information to d7x!]"); } } goto GetUserInput; case ConsoleKey.R: if (_file_d7xEXE.Length > 0) { launchd7x("/regsearch=" + processName); } goto GetUserInput; case ConsoleKey.N: // add to skipped files collection if user specifically skips this file if (!_skippedProcesses.ContainsKey(sSubject)) { _skippedProcesses.Add(sSubject, ""); } break; case ConsoleKey.Escape: break; case ConsoleKey.Y: bKill = true; break; case ConsoleKey.Enter: bKill = true; break; default: goto GetUserInput; } } else { // finally we land here if we aren't in debug mode bKill = true; } } } } if (bKill) { bSuccess = killProcessByPID(PID); if (bSuccess) { // add to successfully terminated processes list if (!_terminatedProcesses.ContainsKey(sSubject)) { _terminatedProcesses.Add(sSubject, ""); } sResult = "True "; // pad an extra space to match length of 'FALSE' for text formatting on screen/in log file } else { sResult = "FALSE"; // set text to uppercase to easily recognize a failure } sbLog.AppendLine($"Terminated={sResult} \"{sSubject}\""); Console.WriteLine($"Terminated={sResult} \"{processName}\""); } else { Console.WriteLine($"Skipped \"{processName}\""); } }
static void pressAnyKeyToExit(string logText) { string savelogText = "Press 'L' to save results to KillEmAll_Log.txt\n"; string runAsAdminText = "Press 'A' to run KillEmAll.NET again (as Administrator) \n"; string pressAnyKeyText = "\nPress any other key to exit. . ."; // if administrator, empty this string so the option isn't printed if (isRunningAsAdmin()) { runAsAdminText = ""; } // construct the rest of the text string runAndConfigText; if (Console.WindowWidth < 120) { runAndConfigText = "Press 'R' to run KillEmAll.NET again\n"; runAndConfigText += "Press 'D' to run KillEmAll.NET again (in Debug Mode)\n"; runAndConfigText += "Press 'C' for KillEmAll.NET Configuration\n"; } else { runAndConfigText = "Press 'R' to run KillEmAll.NET again Press 'C' for KillEmAll.NET Configuration\n"; runAndConfigText += "Press 'D' to run KillEmAll.NET again (in Debug Mode) \n"; } // if we're already flagged to show log on exit, we've been through this method before and specifically selected 'L' to save the log... if (_showTextFileOnClose) { // so automatically log everything else; pass a silent flag because we don't need to see that every time. logTextToFile(logText, true); // and clear this string so the 'L' option isn't shown below savelogText = ""; } PrintMsg: // write a little screen distance Console.WriteLine("\n"); // since we're not running as administrator, prompt user to run again as admin... Console.Write(savelogText + runAndConfigText + runAsAdminText + pressAnyKeyText); GetResponse: ConsoleKeyInfo foo = Console.ReadKey(); switch (foo.Key) { case ConsoleKey.R: startKillEmAll(); return; case ConsoleKey.D: startKillEmAll(true); return; case ConsoleKey.A: if (isRunningAsAdmin()) { goto GetResponse; } // if function returns true, flag this bool = false so we don't pop up the text file when we're relaunching as admin if (launchSelfAsAdministrator()) { _showTextFileOnClose = false; } break; case ConsoleKey.C: System.Windows.Forms.Form config = new ConfigUI(); config.ShowDialog(); goto GetResponse; case ConsoleKey.L: logTextToFile(logText); _showTextFileOnClose = true; Console.Write(runAndConfigText + runAsAdminText + pressAnyKeyText); goto GetResponse; case ConsoleKey.I: Console.Clear(); Console.WriteLine("\nConfig File = " + _iniFile); Console.WriteLine("Allow List = " + _file_AllowList); Console.WriteLine("Log File = " + getLogFilePathAndName()); Console.WriteLine("d7x EXE = " + _file_d7xEXE); goto PrintMsg; } if (_showTextFileOnClose) { string logFile = getLogFilePathAndName(); Process.Start("notepad.exe", logFile); } }