Search code examples
c++windows-services

How see console window of a service during your full execution lifetime?


Probably this already was answered here, but i not found.

Then i want know how execute a c++ console application/service (installs itself as service) of way that i can see all output's (printf()) during your execution (similar to how happens in a normal console application when system("pause");is used in main())? until now i'm able to see you console window only while Avast DeepScreen is executing he :-).

Thanks in advance.


EDITION:

I already insert getchar(); in ServiceMain() and a while (true) ... Sleep() but without success.


Solution

  • A service does not have a console window. And even if it did, a service does not run in an interactive desktop, so you couldn't see such a window anyway.

    You need to rethink your logging approach. Either

    • write your log messages to the Windows Event Log, and use the Windows Event Viewer to see the messages.

    • create a separate visual app that runs in the user's interactive desktop and communicates with the service process to receive log messages. Then you can display the messages however you want.