Detect if external process is interactive and has any visible UI

后端 未结 2 1228
不知归路
不知归路 2021-01-17 03:48

I cannot seem to find a way to determine whether a Process has a user interface e.g. a window, which is visible to the user?

  • Environment.UserInte
2条回答
  •  离开以前
    2021-01-17 04:15

    The MSDN article about System.Diagnostics.Process.MainWindowHandle states the following

    If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, an exception will be thrown.

    What they are implying is that the Window might take several seconds to render after you've made the call for the MainWindowHandle, returning IntPtr.Zero even though you can clearly see a Window is shown.

    See https://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx for reference

提交回复
热议问题