I have a service that needs to run an application (lets call it X) that in tern uses Excel automation.
Often application X when automating Excel will have Excel display a dialog. What and why the dialog displays isn't important, unfortunately that is out of my control.
I'd simply like to be able to close that dialog in Excel.
This of course is easily done when the code doesn't run as a service. The problem is that any win32 window call returns 0 for a handle when enumerating the windows to determine if a dialog is up. I understand why this is as the service runs in isolation and the result of 0 is expected.
It's also not possible that the service runs under local system with interactive desktop enabled.
I was hoping to use the GetThreadDesktop on a thread for the Excel process, then open that Desktop to enumerate those windows, however that api also returns 0 when running from a service.
There are plenty of questions regarding this, however most are about wanting to display a dialog from a service for user interaction. I do not want to do that. Merely find and close a dialog.
Is there a clever workaround to this that someone has discovered to enumerate windows and return the captions ?
Notes:
- Application X is out of my control.
- I know that office automation is not supported in a non-interactive environment.
- I'm not trying to interact with a logged-in user's desktop in anyway.