Commit e0544dd645e128f6715b6782488b14a8d7f424ff
1 parent
98324260
v1.12.0.0
adding menuitem procdump for services
Showing
3 changed files
with
40 additions
and
3 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
@@ -231,6 +231,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | @@ -231,6 +231,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | ||
231 | public static class Start { public const string KEY = "WSS"; } | 231 | public static class Start { public const string KEY = "WSS"; } |
232 | public static class Stop { public const string KEY = "WSX"; } | 232 | public static class Stop { public const string KEY = "WSX"; } |
233 | public static class Kill { public const string KEY = "WSK"; } | 233 | public static class Kill { public const string KEY = "WSK"; } |
234 | + public static class Dump { public const string KEY = "DMP"; } | ||
234 | public static class Purge { public const string KEY = "WSP"; } | 235 | public static class Purge { public const string KEY = "WSP"; } |
235 | } | 236 | } |
236 | } | 237 | } |
Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs
@@ -88,6 +88,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | @@ -88,6 +88,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | ||
88 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Start.KEY, "Start")) | 88 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Start.KEY, "Start")) |
89 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Stop.KEY, "Stop")) | 89 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Stop.KEY, "Stop")) |
90 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Kill.KEY, "Kill")) | 90 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Kill.KEY, "Kill")) |
91 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Dump.KEY, "Dump")) | ||
91 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY, "Set user account")) | 92 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY, "Set user account")) |
92 | .SetSelectionMode(Menu.SelectionMode.Single) | 93 | .SetSelectionMode(Menu.SelectionMode.Single) |
93 | ; | 94 | ; |
@@ -147,6 +148,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | @@ -147,6 +148,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | ||
147 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | 148 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } |
148 | } | 149 | } |
149 | break; | 150 | break; |
151 | + case CLP.Module.WindowsServiceManager.Function.Dump.KEY: | ||
152 | + foreach (var ws in selectedServices) | ||
153 | + { | ||
154 | + try | ||
155 | + { | ||
156 | + var success = WindowsServiceManagerCore.Dump(ws.Name); | ||
157 | + ColorConsole.WriteLine($"Service dump completed. Name:{ws.Name}", ConsoleColor.Green); | ||
158 | + } | ||
159 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | ||
160 | + } | ||
161 | + break; | ||
162 | + break; | ||
150 | case CLP.Module.WindowsServiceManager.Function.Kill.KEY: | 163 | case CLP.Module.WindowsServiceManager.Function.Kill.KEY: |
151 | foreach (var ws in selectedServices) | 164 | foreach (var ws in selectedServices) |
152 | { | 165 | { |
@@ -437,7 +450,30 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | @@ -437,7 +450,30 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS | ||
437 | return true; | 450 | return true; |
438 | } | 451 | } |
439 | } | 452 | } |
440 | - | 453 | + |
454 | + public static bool Dump(string sname) | ||
455 | + { | ||
456 | + using (var wmiService = WindowsServiceManagerCore.GetServiceObject(sname)) | ||
457 | + { | ||
458 | + string sstate = (string)wmiService[nameof(WindowsService.State)]; | ||
459 | + if (sstate != nameof(ObjectState.Stopped)) | ||
460 | + { | ||
461 | + int pid = Convert.ToInt32(wmiService[nameof(WindowsService.ProcessId)]); | ||
462 | + Process p = new Process(); | ||
463 | + p.StartInfo.FileName = "procdump.exe"; | ||
464 | + p.StartInfo.Arguments = $"-accepteula -ma -o {pid} ."; | ||
465 | + //p.StartInfo.FileName = ""; | ||
466 | + p.StartInfo.UseShellExecute = false; | ||
467 | + p.StartInfo.RedirectStandardOutput = true; | ||
468 | + p.Start(); | ||
469 | + string output = p.StandardOutput.ReadToEnd(); | ||
470 | + string logwaiting = "waiting."; | ||
471 | + while (!p.HasExited) { logwaiting += "."; p.WaitForExit(); } | ||
472 | + foreach (var dumpline in output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { ColorConsole.WriteLine(dumpline); ColorConsole.WriteLine(""); } | ||
473 | + } | ||
474 | + return true; | ||
475 | + } | ||
476 | + } | ||
441 | /// <summary> | 477 | /// <summary> |
442 | /// Kill a process, and all of its children, grandchildren, etc. | 478 | /// Kill a process, and all of its children, grandchildren, etc. |
443 | /// </summary> | 479 | /// </summary> |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
32 | // You can specify all the values or you can default the Build and Revision Numbers | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | // by using the '*' as shown below: | 33 | // by using the '*' as shown below: |
34 | // [assembly: AssemblyVersion("1.0.*")] | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.11.5.0")] | ||
36 | -[assembly: AssemblyFileVersion("1.11.5.0")] | 35 | +[assembly: AssemblyVersion("1.12.0.0")] |
36 | +[assembly: AssemblyFileVersion("1.12.0.0")] |