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
I don't think you can do that with the .net framework...
but you can with WinAPI: http://msdn.microsoft.com/en-us/library/ms633497%28v=vs.85%29.aspx
and you can call it from C# like so: http://www.pinvoke.net/default.aspx/user32/enumwindows.html
An important note: your process need to have permissions for this...
you'll also probably need this: http://msdn.microsoft.com/en-us/library/ms633520(v=vs.85).aspx http://www.pinvoke.net/default.aspx/user32.getwindowtext
Services run in session 0, the non-interactive session for services. Desktop applications run in different sessions. Session 1 for the first interactive user, session 2 for the second and so on. Inside the sessions are window stations, and inside window stations are desktops.
Window stations are secured and isolated. That means that a process in one window station cannot access the objects of another. This means that your service cannot use GetWindowText
or indeed any function or message to interact with a window in a different window station.
If you need to transmit this information between the interactive desktops and your service, then you need:
In short, you are going to need to build a bit more scaffolding to get this to work.
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<string> windowTitles = new List<string>();
foreach (Process proc in processList)
{
StringBuilder Buff = new StringBuilder(256);
if (GetWindowText(proc.MainWindowHandle.ToInt32(), Buff, 256) > 0 )
{
windowTitles.Add(Buff.ToString());
}
}