using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; namespace CsActive { class Program { [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetForegroundWindow(IntPtr hWnd); static void Main(string[] args) { //すべてのプロセスを列挙する foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { //"メモ帳"がメインウィンドウのタイトルに含まれているか調べる if (0 <= p.MainWindowTitle.IndexOf("メモ帳")) { //ウィンドウをアクティブにする SetForegroundWindow(p.MainWindowHandle); break; } } } } }