MainWindowTitle Property in Windows Services

  • Thread starter Thread starter Donald Oakes
  • Start date Start date
D

Donald Oakes

I'm experiencing some problems with the
System.Diagnostic.Process.MainWindowTitle property when
accessed from a Window's Service running on XP Pro.

The following code:

foreach (Process process in Process.GetProcesses())
{
Console.Write(process.ProcessName + " : " +
process.MainWindowTitle + "\n");
}

works fine from a console application. But
MainWindowTitle is always an empty string when this
snippet is run from within my Windows Service (also
MainWindowHandle is always returning zero, even for
processes with a graphical interface).

Any advice would be greatly appreciated.
 
I'm pretty sure that this is because the service doesn't have access to the
user WindowStation. Did you try enabling the "allow interaction with
desktop"?

If it still doesn't work, you may need to resort to using Pinvoke and the
API so that you can open the handles with full privileges.

Jerry
 
Jerry,

Thanks very much. The "allow interaction with desktop"
enablement was indeed the problem.

- Don
 
Back
Top