0

We need to get the last active window's title of a process.

Currently We are using the command tasklist /v and parsing it to get the window title.

Problem:

We are not able to get the last active window's title if we run the command under system account in services.

Output If we run under windows account/system account (not from services):

Image Name PID  Session Name Session# Mem Usage Status   User Name CPU Time Window Title                                  
firefox.exe    4476 Console          1             509,224 K    Running Ramesh     0:01:47     Getting the window title of a process

Output If we run under windows account/system account (from services):

Image Name PID  Session Name Session# Mem Usage Status   User Name CPU Time Window Title
firefox.exe    4476 Console          1             509,224 K    Running Ramesh     0:01:47     N/A              

Our application is running under system account from services. Is there a way to get the windows title from a program running under system account from services?

Ramesh Durai
  • 2,666
  • 9
  • 32
  • 55
  • Can anyone suggest improvements or corrections to this? – Ramesh Durai Jun 24 '14 at 05:03
  • It's not even clear what "*the* window title" is: A process can have many windows with different titles. I don't think you'd be able to do anything useful without some code to dig out the top-level windows and somehow decide which is the one you're referring to as "the" window. Here's one pointer - http://stackoverflow.com/questions/6202547/win32-get-main-wnd-handle-of-application – Ofek Shilon Jun 24 '14 at 15:10
  • @OfekShilon If you run the command 'tasklist /v' in the command prompt, you will get a column called window title which will have the `last active window of a process multiple windows`. That's what i want. – Ramesh Durai Jun 25 '14 at 04:14

1 Answers1

3

In Windows Vista and later Windows service run in a separate session. When a user logs in a Terminal Services enabled computer a new session is created with each logon. That's the reason we are not able to access the window title of a process since it is running under different session.

However, an interactive service can display a user interface and receive user input. To access the window title of the process in another user's session, I need to create an interactive services.

MSDN article: Interactive services.

Ramesh Durai
  • 2,666
  • 9
  • 32
  • 55