/// <summary> /// Gets the process ID of the process that created the first window to match the given window title. /// </summary> /// <param name="Classname">Classname of the main window whose process id we want.</param> /// <returns>Returns non-zero on success, zero on failure.</returns> public static int GetProcessFromClassname(string Classname) { IntPtr hWnd = SWindow.FindWindow(Classname, null); if (hWnd == IntPtr.Zero) { return(0); } return(GetProcessFromWindow(hWnd)); }
/// <summary> /// Gets the process ID of the process that created the first window to match the given window title. /// </summary> /// <param name="WindowTitle">Title of the main window whose process id we want.</param> /// <returns>Returns non-zero on success, zero on failure.</returns> public static int GetProcessFromWindowTitle(string WindowTitle) { IntPtr hWnd = SWindow.FindWindow(null, WindowTitle); if (hWnd == IntPtr.Zero) { return(0); } return(GetProcessFromWindow(hWnd)); }
/// <summary> /// Returns an array of process ids of processes that match given window title. /// </summary> /// <param name="WindowTitle">Title of windows to match.</param> /// <returns>Returns null on failure, array of integers populated with process ids on success.</returns> public static int[] GetProcessesFromWindowTitle(string WindowTitle) { IntPtr[] hWnds = SWindow.FindWindows(null, WindowTitle); if (hWnds == null || hWnds.Length == 0) { return(null); } int[] ret = new int[hWnds.Length]; for (int i = 0; i < ret.Length; i++) { ret[i] = GetProcessFromWindow(hWnds[i]); } return(ret); }
//##OPEN############################################################### /// <summary> /// Opens a process and its main thread for interaction. /// </summary> /// <param name="ProcessId">Process Id of process with which we wish to interact.</param> /// <returns>Returns true on success, false on failure.</returns> public bool Open(int ProcessId) { if (ProcessId == 0) { return(false); } if (ProcessId == m_ProcessId) { return(true); } if (m_bProcessOpen) { this.CloseProcess(); } if (SetDebugPrivileges) { System.Diagnostics.Process.EnterDebugMode(); } m_bProcessOpen = (m_hProcess = SProcess.OpenProcess(ProcessId)) != IntPtr.Zero; if (m_bProcessOpen) { m_ProcessId = ProcessId; m_hWnd = SWindow.FindWindowByProcessId(ProcessId); m_Modules = System.Diagnostics.Process.GetProcessById(m_ProcessId).Modules; m_MainModule = m_Modules[0]; if (Asm == null) { Asm = new ManagedFasm(m_hProcess); } else { Asm.SetProcessHandle(m_hProcess); } } return(m_bProcessOpen); }