Tengo una aplicación que quiero ejecutar en segundo plano. Quiero obtener el nombre del ejecutable, por ejemplo IExplorer.exe. He jugado con el siguiente código:C# obtener información sobre la ventana activa actual
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
public static void Main()
{
int chars = 256;
StringBuilder buff = new StringBuilder(chars);
while (true)
{
// Obtain the handle of the active window.
IntPtr handle = GetForegroundWindow();
// Update the controls.
if (GetWindowText(handle, buff, chars) > 0)
{
Console.WriteLine(buff.ToString());
Console.WriteLine(handle.ToString());
}
Thread.Sleep(1000);
}
}
Eso solo me da el título de la ventana y el ID del identificador. Quiero obtener el nombre del ejecutable (y tal vez más información).
¿Cómo logro eso?
mirada a la última respuesta de esta pregunta en stackOverflow: http://stackoverflow.com/questions/7268302/get-the-titles-of-all-open-windows/31517889#31517889 – Godvicien