public List <string> ToString(params ProcessInfo[] fields) { List <string> window = new List <string>(); foreach (ProcessInfo field in fields) { switch (field) { case ProcessInfo.isActive: window.Add(this.isAlive().ToString()); break; case ProcessInfo.pid: window.Add(this.hWnd.ToString()); break; case ProcessInfo.fileName: window.Add(this.imageFileName); break; case ProcessInfo.title: window.Add(WindowProcessor.GetWindowText(this.hWnd)); break; case ProcessInfo.timeRegistered: window.Add(this.timeRegistered.ToString()); break; default: break; } } return(window); }
static void Main(string[] args) { if (args.Contains("--verbose")) { showConsole = true; } else { HideConsole(); } Log("Started pid: " + WindowProcessor.GetCurrentProcessId().ToString()).Wait(); while (true) { IDictionary <IntPtr, WindowProcess> windows = WindowProcessor.GetOpenWindowProcesses(); if (showConsole) { Console.Clear(); Console.WriteLine(windows.Values.ToStringTable( new[] { " * ", "HID", "PID", "isAlive", "FileName", "Title" }, window => (window.isActive() ? " * " : " "), window => window.hWnd, window => window.pid, window => (window.isAlive() ? " + " : " "), window => window.imageFileName, window => Truncate(window.GetWindowText(), 50) )); } IEnumerable <WindowProcess> wnd = windows.Values.Where(window => window.isActive()); if (wnd.Count() > 0) { data.user = System.Security.Principal.WindowsIdentity.GetCurrent().Name; data.hid = wnd.First().hWnd.ToString(); data.pid = wnd.First().pid.ToString(); data.filename = wnd.First().imageFileName; data.title = wnd.First().GetWindowText(); try { post(data).Wait(); } catch (Exception ex) { if (showConsole) { Console.Out.WriteLine(ex.Message); } else { Log(ex.Message).Wait(); } } } Thread.Sleep(5 * 1000); } }
private static bool HideConsole() { var hwnd = WindowProcessor.GetConsoleWindow(); WindowProcessor.GetWindowThreadProcessId(hwnd, out var pid); if (pid != Process.GetCurrentProcess().Id) { return(false); } WindowProcessor.ShowWindow(hwnd, SW_HIDE); return(true); }
public WindowProcess(IntPtr hWnd) { this.hWnd = hWnd; try { this.pid = WindowProcessor.GetProcessId(hWnd); this.imageFullPath = WindowProcessor.GetProcessFilePath(this.pid); // imageFolderName = Path.GetDirectoryName(imageFullPath); this.imageFileName = Path.GetFileName(imageFullPath); this.windowText = WindowProcessor.GetWindowText(hWnd); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } finally { this.timeRegistered = DateTime.Now; } }
public string GetWindowText() { return(WindowProcessor.GetWindowText(this.hWnd)); }
public bool isActive() { return(WindowProcessor.IsActive(this.hWnd)); }
public bool isAlive() { return(WindowProcessor.GetProcessId(this.hWnd) == this.pid); }