Search code examples
c++winapiwindows-servicesenumerate

can windows service enumerate desktop top level windows


I'm trying to enumerate top level windows from a service coded in c++ I want to find a particular program which there are multi instances of it running but I want a particular one which have some unique words in its window title

so I'm using this code :

 auto desktop = OpenInputDesktop( 0, FALSE, DESKTOP_READOBJECTS);
 if (!desktop) log_file << "[*] OpenDesktopA failed with error : " << GetLastError() << endl;
BOOL rs = EnumDesktopWindows(desktop, EnumProc, 0);
if (!rs) log_file << "[*] EnumDesktopWindows failed with error : " << GetLastError() << endl;

the EnumDesktopWindows fails without calling the EnumProc so GetLastError returns zero

the same code works in non sevice program

is it possible to do this in a service but I'm doing something wrong ? or I can't achieve this ?


Solution

  • the final solution seems to make a helper process which will list the windows and find the id of the required windows the send it to the service through pipes or sockets or other communication techniques