C# Raise an event when a new process starts

前端 未结 4 1794
再見小時候
再見小時候 2020-12-10 04:34

Hey there, Is there a way to raise event when a new process is started without using the ManagementEventWatcher, and without using the Process.GetProcesses()? The problem wi

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 05:16

    Strange thing is an application does not need to create a window in windows. Create process may not belong to the window-station that you work on. You will need to find windows of that process anyway, and you will also need to detect new and closed windows of all processes.

    So enumerating windows is much cleaner/easier choice.

    Try EnumChildWindows function on desktop handle (retrieved by GetDesktopWindow) to find top level windows of applications. use GetWindowThreadProcessId and EnumThreadWindows on obtained handles to detect sub windows of windows.

    A low priority thread will do the job.

提交回复
热议问题