Sometimes there is need to open new program (e.g. Windows Powerpoint presentation as slideshow can be opened by command line “powerpnt.exe /s“) from commandline, maximize this program and bring it in front of desktop as the first program the user can see and use. This happens by default if user directly enters command in the command prompt, because the command prompt is the active window.
But the question is – how to do this, if command line is executed from background process – e.g. from custom Windows service application of from the Windows Task Scehduler – in both cases the new windows is not brought as the first window.
At present I can imagine only quite hard solutions (whose drawback is that they required coding and they can not be used from Task Scheduler):
- one can try to get handle of the main window of the opened program and the manipulate this window – e.g. maximize and so on;
- one can try to abandon command line at all and instead manipulate Windows Office applications as COM objects.
Maybe there is easier way?
You can create a small (non-gui) launcher application that will call the new program for you (I know, that’s what you’ve called the hard solution) and then schedule this launcher on the task scheduler.
This launcher application would have to create de process (CreateProcess function), and then get the Window Handle from the pID… with the window handle you can use SetForegroundWindow to do what you need, or call other functions for things like maximize, etc.
Since you tagged delphi, I’m posting a possible delphi implementation of that.
Hope that’s what you need.. sorry if it’s not.
Best Regards.