MainWindowTitle Property in Windows Services

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.
 
J

Jerry Ham

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
 
D

Donald Oakes

Jerry,

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

- Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top