B4J Question How to view program main form if started before the user login?

amorosik

Expert
Licensed User
I have a procedure created in B4J that has a single form for displaying internal activity
When it is started, the main form is iconized and remains in the tray-bar, with a double-click on the icon at the bottom right I can bring the main form back to full visibility
It is a kind of print spooler that receives jobs from external programs, converts them to PDF, and sends them to printer
This program is active 24 hours a day and is installed on a PC with a Win10 professional operating system
The program start-up is done via Windows scheduled tasks and is set to start even without user login
And so if I turn on the PC that hosts this program, even without having logged in as a user, the program is regularly running and works correctly
This operating mode has been designed to ensure that the program is active whether the user is logged in or not

The problem is that when I log in as a user, I see the program as active in the Task Manager, but I can no longer access its main window
The only way is to perform an 'end application' and re-launch the program, which I would not like to do because you risk losing print commands

The question is: without interrupting the execution of the program, how to obtain the visibility of the main screen when the procedure started before the user login?
(currently it is not possible because I do not see the icon in the tray-bar)
 

Chris2

Active Member
Licensed User
Longtime User
The question is: without interrupting the execution of the program, how to obtain the visibility of the main screen when the procedure started before the user login?
I think the answer is that you can't. But you can work around it...

I have also used Windows Task Scheduler to start programs before user log in and have faced the same problem. I have overcome it in two different ways which suit different circumstances:

Option 1:
Split the program in two, creating a non-UI app to do the work and a UI app which just displays what the non-UI app is doing/has done. You can then use Task Scheduler to start the non-ui app before the user logs in, and then only fire up the UI 'front-end' app when Windows log-in occurs.

Option 2:
Create a mechanism in your app which checks on app start if an instance of the app is already running. If it is you can use jShell ('taskkill') to forcibly close it, or (my preferred method) add handling of UDP messages in your app and send a 'close' message to the 'hidden' app so that you can close it down in a more controlled way than 'taskkill' allows.
With either of these app closing options, use Task Scheduler to start the app before Windows user login and also have it auto-start after Windows user log in.
When Windows log-in occurs the new instance of the app starts up, closes the 'hidden' one and then finishes starting up showing the main form which was previously hidden.


There are probably other routes you could take as well, but these are the two that I've used with some success.
 
Last edited:
Upvote 0

amorosik

Expert
Licensed User
Yes, I was afraid of having to take path 1, I hoped there was some trick, but obviously you can't always be lucky
I didn't understand path 2, because it involves interrupting the program execution and then quickly restarting it
But avoiding the program interruption is one of the requests that I intend to respect and therefore I think that if better paths don't come up, I will have to follow option 1
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
I didn't understand path 2, because it involves interrupting the program execution and then quickly restarting it
But avoiding the program interruption is one of the requests that I intend to respect and therefore I think that if better paths don't come up, I will have to follow option 1
Yes, I realised that option 2 doesn't strictly adhere to the 'avoiding program interuption' rule. But given that you're in control of how the 1st (hidden) instance of the program closes while the 2nd (viewable) instance is already running, I wondered if there might be a way that you could make sure nothing was missed.
 
Upvote 0
Top