From e0544dd645e128f6715b6782488b14a8d7f424ff Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Thu, 1 Sep 2022 16:44:53 +0200 Subject: [PATCH] v1.12.0.0 adding menuitem procdump for services --- Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs | 1 + Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs | 38 +++++++++++++++++++++++++++++++++++++- Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs index 2c24f07..dffe79d 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs @@ -231,6 +231,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS public static class Start { public const string KEY = "WSS"; } public static class Stop { public const string KEY = "WSX"; } public static class Kill { public const string KEY = "WSK"; } + public static class Dump { public const string KEY = "DMP"; } public static class Purge { public const string KEY = "WSP"; } } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs index de1eb31..886d676 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs @@ -88,6 +88,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Start.KEY, "Start")) .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Stop.KEY, "Stop")) .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Kill.KEY, "Kill")) + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Dump.KEY, "Dump")) .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY, "Set user account")) .SetSelectionMode(Menu.SelectionMode.Single) ; @@ -147,6 +148,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } } break; + case CLP.Module.WindowsServiceManager.Function.Dump.KEY: + foreach (var ws in selectedServices) + { + try + { + var success = WindowsServiceManagerCore.Dump(ws.Name); + ColorConsole.WriteLine($"Service dump completed. Name:{ws.Name}", ConsoleColor.Green); + } + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } + } + break; + break; case CLP.Module.WindowsServiceManager.Function.Kill.KEY: foreach (var ws in selectedServices) { @@ -437,7 +450,30 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS return true; } } - + + public static bool Dump(string sname) + { + using (var wmiService = WindowsServiceManagerCore.GetServiceObject(sname)) + { + string sstate = (string)wmiService[nameof(WindowsService.State)]; + if (sstate != nameof(ObjectState.Stopped)) + { + int pid = Convert.ToInt32(wmiService[nameof(WindowsService.ProcessId)]); + Process p = new Process(); + p.StartInfo.FileName = "procdump.exe"; + p.StartInfo.Arguments = $"-accepteula -ma -o {pid} ."; + //p.StartInfo.FileName = ""; + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + p.Start(); + string output = p.StandardOutput.ReadToEnd(); + string logwaiting = "waiting."; + while (!p.HasExited) { logwaiting += "."; p.WaitForExit(); } + foreach (var dumpline in output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { ColorConsole.WriteLine(dumpline); ColorConsole.WriteLine(""); } + } + return true; + } + } /// /// Kill a process, and all of its children, grandchildren, etc. /// diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index a6f4b30..6e51a73 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 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.11.5.0")] -[assembly: AssemblyFileVersion("1.11.5.0")] +[assembly: AssemblyVersion("1.12.0.0")] +[assembly: AssemblyFileVersion("1.12.0.0")] -- libgit2 0.21.2