Board index » delphi » Stopping an app server from another app

Stopping an app server from another app

2008-03-13 12:44:45 AM
I have built a middle tier using D7, TRemoteDataModule.
The Borland Socket Server (BSS)/TSocketConnection is used as the
communication method between the clients and the application server.
I installed the BSS as a service, and I unchecked the service property
checkbox "Allow service to interact with desktop". This is necessary,
because when the BSS is loaded as a service, and if the BSS icon is
visible in the system tray, and some one tries to right click,
properties, and edits the properties, the BSS will often crash, and all
my users get locked out, until I "End Task" the BSS and restart it. I
suspect this may because something in the interface of the BSS is not
thread safe. Otherwise, the BSS works great for us.
There is a consequence to unchecking the "Allow service to interact
with desktop" checkbox for the BSS process however, and that is, any
application server the BSS calls, is also prevented from interacting
with the desktop. So the options controls I had put in my app server
are not visible to the administrator. To get around this, I took a
lesson from Firebird, where the Firebird service runs in the
background, and the little Firebird Server Manager can stop/start the
service, and edit options.
I proceeded to build an "Options Editor" which does nothing more than
allow the administrator to edit the .ini file using a GUI. The one
last function my Options Editor has to do is allow the user to stop the
running application server.
The problem:
When the BSS (running as a "non-desktop interactive" service) starts an
application server because a client is trying to connect, the
application is not running like it does when started from Explorer and
the main window of the app server is showing, in which case, I can
simply use FindWindow and SendMessage to close it. (So in this
situation, FindWindow doesn't work)
Further, it is not running as a service either.. it is not listed in the
Windows Services, so I can not use SERVICE_CONTROL_STOP as described in
Torry pages. (I tried, using the funny name described below)
The only place the app server is listed, when it is running in this way,
is in Task Manager, in the "Processes" tab, and then, it has a funny
"Image name" with a tilde (~) in the name with an integer appended
(like: MYAP~2)
What Delphi/Windows API call(s) should I be using to:
a) Locate the running "hidden" process
b) Close the running "hidden" process
Thanks in advance.

Re:Stopping an app server from another app

I found the following link helpful:
However I found to make the solution work I had to change the
"OpenProcess" line to read:
hProc := OpenProcess(PROCESS_ALL_ACCESS, TRUE, cdsProcessID.AsInteger);