C# 현재 사용중인 프로세스 찾기
예제 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Input; namespace Test { class Program { [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern Int32 GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); static void Main(string[] args) { int a = 0; while (a++ < 10) { Thread.Sleep(1000); IntPtr hwnd = GetForegroundWindow(); uint pid; if (hwnd == null) continue; GetWindowThreadProcessId(hwnd, out pid); Process CurProc = Process.GetProcessById((int)pid); var name = CurProc.MainWindowTitle; Console.WriteLine(name); } } } } | cs |
반응형
'Programming > C/C++/C#' 카테고리의 다른 글
C# - 파일 존재 여부 확인방법 (0) | 2015.12.24 |
---|---|
C++ - 연산자 operator (0) | 2015.12.16 |
C++ - 포인터를 이용해 배열 만들기 (0) | 2015.12.01 |
C# - 주석처리 기능 summary (0) | 2015.08.27 |
C# - 프로퍼티 set; get; (0) | 2015.08.16 |
C - for while 별 그리기 (0) | 2015.06.19 |
C# - Process 시작, 종료 (0) | 2015.05.28 |
기본 자료형의 종류와 연산자 (0) | 2015.05.13 |