Getting window titles from a windows service

后端 未结 3 2104
庸人自扰
庸人自扰 2020-12-21 11:55

My company is using an unfortunate third party product that requires a user to be left logged on to an XP workstation running two instances of it\'s product.

I was t

3条回答
  •  一整个雨季
    2020-12-21 12:44

    using System.Runtime.InteropServices;
    using System.Text;
    

    ...

    [DllImport("user32.dll")]
    static extern int GetWindowText(int hWnd, StringBuilder text, int count); 
    

    ...

    Process[] processList = Process.GetProcesses();
    
    List windowTitles = new List();
    
    foreach (Process proc in processList)
    {
        StringBuilder Buff = new StringBuilder(256);
    
        if (GetWindowText(proc.MainWindowHandle.ToInt32(), Buff, 256) > 0 )
        {
            windowTitles.Add(Buff.ToString());
        }
    }
    

提交回复
热议问题