Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Service with no UI


This question is answered.


Permlink Replies: 25 - Last Post: Mar 31, 2017 12:45 AM Last Post By: Angus Robertson
Patrick Charles

Posts: 13
Registered: 7/13/99
Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 4:12 AM
Hi all,

Is there a way to write services in Delphi 10 Seattle in a way that would not rely on the VCL at all?
The idea is to be able to run these services on Windows Server Core and eventually on Windows Nano Server.

Thank you.

Patrick

Lars Fosdal


Posts: 156
Registered: 10/26/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 4:22 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:
Hi all,

Is there a way to write services in Delphi 10 Seattle in a way that would not rely on the VCL at all?
The idea is to be able to run these services on Windows Server Core and eventually on Windows Nano Server.

Won't the standard Service Application skeleton won't run on Windows Server Core?
Is it the use of Vcl.Forms, Vcl.Dialogs, Vcl.Consts in the implementation section of Vcl.SvcMgr that is a problem?
AFAIK, it doesn't instantiate any UI elements?

--
http://plus.lars.fosdal.com
Delphi Developers Google+ Community: https://plus.google.com/communities/103113685381486591754 (8500+ members)
Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 5:03 AM   in response to: Lars Fosdal in response to: Lars Fosdal
Lars Fosdal wrote:
Patrick Charles wrote:
Hi all,

Is there a way to write services in Delphi 10 Seattle in a way that would not rely on the VCL at all?
The idea is to be able to run these services on Windows Server Core and eventually on Windows Nano Server.

Won't the standard Service Application skeleton won't run on Windows Server Core?
Is it the use of Vcl.Forms, Vcl.Dialogs, Vcl.Consts in the implementation section of Vcl.SvcMgr that is a problem?
AFAIK, it doesn't instantiate any UI elements?

--
http://plus.lars.fosdal.com
Delphi Developers Google+ Community: https://plus.google.com/communities/103113685381486591754 (8500+ members)

Thank you for the quick response Lars,

I created a small service hat does nothing but log in the application event log when the service is created, destroyed, starts and stops.
It also inserts data in the registry for the event logging on after install and deletes it on after uninstall.
I compiled it in 64 bit and built it without the packages, the size is a bit over 3500KB. When I build it with the rtl, vcl, vcldb, the size goes down to 108KB.
Running the exe through the dependency walker, I can see that it relies on both the rtl and vcl packages.

I am wondering if there is a way to not rely on the vcl at all, because it would be nice for the services to be as small as possible, especially when we move to server core.

Than you.

Patrick

Lars Fosdal


Posts: 156
Registered: 10/26/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 5:46 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:
I created a small service hat does nothing but log in the application event log when the service is created, destroyed, starts and stops.
It also inserts data in the registry for the event logging on after install and deletes it on after uninstall.
I compiled it in 64 bit and built it without the packages, the size is a bit over 3500KB. When I build it with the rtl, vcl, vcldb, the size goes down to 108KB.
Running the exe through the dependency walker, I can see that it relies on both the rtl and vcl packages.

I am wondering if there is a way to not rely on the vcl at all, because it would be nice for the services to be as small as possible, especially when we move to server core.

The nano in Windows Server Nano Server isn't really related to size in memory/disk capacity, but size in OS installation, since it has no local console/ local login capability or UI at all, no no GP support, no SCCM support, etc.
Since your service .exe size doesn't necessarily relate to the actual runtime size, I wouldn't really worry about that part.

I don't know how a nano server behaves with respect to "current user" context use, such as logged in user, working directories, user directories, HKCU, etc.?
Perhaps that is a bigger challenge?


--
http://plus.lars.fosdal.com
Delphi Developers Google+ Community: https://plus.google.com/communities/103113685381486591754 (8500+ members)

Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 7:24 AM   in response to: Lars Fosdal in response to: Lars Fosdal
Lars Fosdal wrote:

I don't know how a nano server behaves with respect to "current user"
context use, such as logged in user, working directories, user
directories, HKCU, etc.? Perhaps that is a bigger challenge?

Same as any other windows, services need an user, most of the time it
will be the default System user.

Anyone doing Windows Services properly will have no problems in nano
Server.

If one found any problem, it will mostly be related to bad practice.


Cesar Romero

Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 7:29 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:

I am wondering if there is a way to not rely on the vcl at all,
because it would be nice for the services to be as small as possible,
especially when we move to server core.

Using Delphi TService there is no way, you can implement your own
avoiding vcl, at your own risk.

TService is well tested and you have people using it all over the
world, your own implementation may have fails and only you/your
customers will be testing it, you should analyse if it worst.

mORMot has an TService implementation, I don't know if it relies on VCL.

Based on that information, I prefer keep the Delphi implementation, I
dont see why less bytes will make my app better in that case.

PS: vcldb, should not be there unless you are using Database Components.
rtl and vcl is part of any Delphi compiled application.


Regards,

Cesar Romero

Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 9:39 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar Romero wrote:
Patrick Charles wrote:

I am wondering if there is a way to not rely on the vcl at all,
because it would be nice for the services to be as small as possible,
especially when we move to server core.

Using Delphi TService there is no way, you can implement your own
avoiding vcl, at your own risk.

TService is well tested and you have people using it all over the
world, your own implementation may have fails and only you/your
customers will be testing it, you should analyse if it worst.

mORMot has an TService implementation, I don't know if it relies on VCL.

Based on that information, I prefer keep the Delphi implementation, I
dont see why less bytes will make my app better in that case.

PS: vcldb, should not be there unless you are using Database Components.
rtl and vcl is part of any Delphi compiled application.


Regards,

Cesar Romero

From what I understand, core and nano do not provide UI functionalities which is good because I don't need any, but this is also why I am a bit concerned about having my service depending on the VCL.
I plan to use a database connection at one time, so yes I will eventually need VCLDB.

My only concern about the size is that it indicates that the binary depends on the VCL, while the OS may not provide any UI functionality.

TService is well tested and I have used it a lot, I am not questioning it.

I am just surprised that a service, that does not display any form, control or dialog depends on the VCL.
My questions are just why? and is there a way to avoid it?

Maybe I should just write a console application, or use a different technology.

Patrick

Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 10:39 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:

From what I understand, core and nano do not provide UI
functionalities which is good because I don't need any, but this is
also why I am a bit concerned about having my service depending on
the VCL. I plan to use a database connection at one time, so yes I
will eventually need VCLDB.

I suspect that VCLDB depends on VCL, just a clue based on the package
name.

My only concern about the size is that it indicates that the binary
depends on the VCL, while the OS may not provide any UI functionality.

Why the size is a matter? Missing disk space?

The size you posted for compilation with packages do not correspond the
reality, even if you remove VCL and VCLDB, the final size of the .exe
will be gibber when standalone .exe, for package compilation, it will
be bigger, the packages you depend on must be send together, and then
you lost the advantage of smart link to remove code you are not using
in your app.

About dependency walker, you must understand that it will list any
dependency listed in your application, even if you only need a class or
a constant, on the other hand, your application will contain only the
bytes that it is using, that is what the smart link do for you when you
compile a Delphi Application.


TService is well tested and I have used it a lot, I am not
questioning it.

I am just surprised that a service, that does not display any form,
control or dialog depends on the VCL. My questions are just why? and
is there a way to avoid it?

Bad design, VCL contains non UI classes needed by TService.

If you have time to spot the unit/class dependency, please open a
request in QP to improvement and post the link here, I'll be happy to
vote for it.


Maybe I should just write a console application, or use a different
technology.

That is up to you, actually TService is a spacial kind on console
application, Delphi, vcl and rtl do a lot make your developmento work
easier, if 2mb of code justify you do all the work manually, then go
for it.


Regards,

Cesar Romero

Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 11:01 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar Romero wrote:

I am just surprised that a service, that does not display any form,
control or dialog depends on the VCL. My questions are just why?
and is there a way to avoid it?

Just a fast look at TService code I can see it depends on
Vcl.Forms.Application, the necessary part could/should be refactored
and put in RTL.

Other than that, only WIndows library hooks, anything else from VCL
will be added to your final .exe, only if you explicity add to your
project.

Regards,

Cesar Romero

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 11:08 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar wrote:

Bad design, VCL contains non UI classes needed by TService.

No quite. Most of the non-UI stuff is in the RTL, not the VCL. The only
VCL dependancies that TService has are the Vcl.Forms and Vcl.Dialogs units
(Vcl.Forms is a massive unit by itself, though). The SvcMgr.TServiceApplication
class uses Vcl.Forms.TApplication internally as part of its internal message
handling (that, I would agree could be considered bad design), and uses MessageDlg()
to display error messages during service (un)installation (would could have
been done using Windows.MessageBox() instead).

--
Remy Lebeau (TeamB)
Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 11:36 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

No quite. Most of the non-UI stuff is in the RTL, not the VCL. The
only VCL dependancies that TService has are the Vcl.Forms and
Vcl.Dialogs units (Vcl.Forms is a massive unit by itself, though).
The SvcMgr.TServiceApplication class uses Vcl.Forms.TApplication
internally as part of its internal message handling (that, I would
agree could be considered bad design), and uses MessageDlg() to
display error messages during service (un)installation (would could
have been done using Windows.MessageBox() instead).

Yes, the messagedlg is the bad design, but all the basics of the
application, the message hook and the abstraction of the windows
message should be separated from vcl. We take the advantage of the
smart link, but it is not clear for most people how it works or even
that it exist.

I have done it in my framework, and the application bootstrap loads the
registered implementation, even decide which one to load, based on how
the application is started, so far I have:

TExecuteMode = (
Console,
WindowsApplication,
WindowsService,
DebugWindowsService,
Update,
Test
);

I have also abstracted the "MessageDlg" to a TMessageBox class, that
must be hooked to the implementation in the bootstrap.

That is just the start, a have a lot more for Views, binding,
notifications, etc. Now I can run the same application as Console,
Windows VCL, Windows Service, Debug Windows Service easily.

I have not done any Windows/MacOS FMX apps, but I shared most of the
code in Android development as well.

Regards,

Cesar Romero

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 11:59 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar wrote:

Yes, the messagedlg is the bad design, but all the basics of the
application, the message hook and the abstraction of the windows
message should be separated from vcl.

Not going to happen in VCL, it is tied very intimately to the Win32 API and
UI handling. And given that Borland/CodeGear/Embarcadero never felt the
need to make updates to the SvcMgr unit despite repeated requests over the
years, don't expect this separation to remove the VCL dependancy from the
TService class to ever happen.

--
Remy Lebeau (TeamB)
Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 12:27 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Not going to happen in VCL, it is tied very intimately to the Win32
API and UI handling. And given that Borland/CodeGear/Embarcadero
never felt the need to make updates to the SvcMgr unit despite
repeated requests over the years, don't expect this separation to
remove the VCL dependancy from the TService class to ever happen.

I do not expect to happen, that is why I have my own implementation, as
it is essential for my business, I did not even bother to open a qc/qp
for that.

Regards,

Cesar Romero

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2017 10:59 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick wrote:

Is there a way to write services in Delphi 10 Seattle in a way
that would not rely on the VCL at all?

Sure, just use the Win32 API directly. MSDN has a full tutorial and code
exaples showing how to write a service using just the SCM API (which is what
TService wraps):

About Services
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681921.aspx

Service Programs
https://msdn.microsoft.com/en-us/library/windows/desktop/ms685967.aspx

The idea is to be able to run these services on Windows Server Core
and eventually on Windows Nano Server.

What makes you think you can't use the VCL TService class for that?

--
Remy Lebeau (TeamB)
Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 4:27 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Patrick wrote:

Is there a way to write services in Delphi 10 Seattle in a way
that would not rely on the VCL at all?

Sure, just use the Win32 API directly. MSDN has a full tutorial and code
exaples showing how to write a service using just the SCM API (which is what
TService wraps):

About Services
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681921.aspx

Service Programs
https://msdn.microsoft.com/en-us/library/windows/desktop/ms685967.aspx

The idea is to be able to run these services on Windows Server Core
and eventually on Windows Nano Server.

What makes you think you can't use the VCL TService class for that?

--
Remy Lebeau (TeamB)

Thank you for the valuable information Remy,

I guess that I was concerned about deploying binaries containing UI forms and dialogs in an OS that doesn't support them.
I would also find a bit sad to have to deploy a 3500KB if I really only need 100KB, but I could leave with that.
I would prefer to keep the size low, because this is why we want to use nano after all and maybe start using docker containers to deploy some components.

If I can be sure that there won't be any problem as long as my code doesn't try to access any UI component, then I can give it a try.
I never wrote a service popping up a dialog anyway.
Do you foresee calling Application.ProcessMessages for example to cause any problem?

Thank you.

Patrick

Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 5:10 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:

I would also find a bit sad to have to deploy a 3500KB if I really
only need 100KB, but I could leave with that. I would prefer to keep
the size low, because this is why we want to use nano after all and
maybe start using docker containers to deploy some components.

As I told you in the other message, 100KB is not the real size, that is
the size of your own code only, you still have to boot the application
and interact with the SO and process all windows messages, that is what
you get from RTL and little part of VCL. You need a lot more code than
your own code to run the Windows Serviuce, in the end, you will have
less than 3500BK, but I suspect nothing near 100KB.

Regards,

Cesar Romero

Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 6:15 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar Romero wrote:
Patrick Charles wrote:

I would also find a bit sad to have to deploy a 3500KB if I really
only need 100KB, but I could leave with that. I would prefer to keep
the size low, because this is why we want to use nano after all and
maybe start using docker containers to deploy some components.

As I told you in the other message, 100KB is not the real size, that is
the size of your own code only, you still have to boot the application
and interact with the SO and process all windows messages, that is what
you get from RTL and little part of VCL. You need a lot more code than
your own code to run the Windows Serviuce, in the end, you will have
less than 3500BK, but I suspect nothing near 100KB.

Regards,

Cesar Romero


You are correct Cesar,

Anyway, the size of the 64bit vcl230.bpl package is over 5,500KB.
I would prefer not to have to deploy it although, as I wrote, I could leave with that.

Patrick
Cesar Romero


Posts: 462
Registered: 3/22/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 11:11 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick Charles wrote:

Anyway, the size of the 64bit vcl230.bpl package is over 5,500KB.
I would prefer not to have to deploy it although, as I wrote, I could
leave with that.

Hi Patrick,

Read again my answers, Delphi has a smarlink, it will not add the whole
vcl in your .exe, it will add only the pieces used by your app.

If you check the size of RTL + VCL, you will see that it is way bigger
that your .exe size, 3500KB.

You will get the whole size only if you distribute your app as packages
(I do not recomend for most cases), for static compilation, the .exe
will contain your code + the parts used from rtl and vcl.

Regards,

Cesar Romero

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 12:07 PM   in response to: Patrick Charles in response to: Patrick Charles
Patrick wrote:

Anyway, the size of the 64bit vcl230.bpl package is over 5,500KB.
I would prefer not to have to deploy it although, as I wrote, I
could leave with that.

You would have to deploy that file only if you compile your EXE with runtime
packages enabled. If you disable them, the RTL/VCL code will be compiled
directly into your EXE instead, and the compiler/linker will eliminate any
RTL/VCL code that is not actually being used.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 12:04 PM   in response to: Patrick Charles in response to: Patrick Charles
Patrick wrote:

I guess that I was concerned about deploying binaries containing
UI forms and dialogs in an OS that doesn't support them.

TService does not have any UI Form in it. It only has a popup dialog, but
only when (un)installing the service on the command-line (and you can disable
that dialog usin the '/silent' command-line switch).

Don't be confused by the fact that the SvcMgr unit has a dependency on the
VCL's Forms and Dialogs unit. That is a different issue.

I would prefer to keep the size low

Then you will have to resort to using the Win32 API directly, and not the
TService wrapper at all.

Do you foresee calling Application.ProcessMessages for example
to cause any problem?

There is no need to call that at all in a service. TService runs in a worker
thread that has its own message loop.

--
Remy Lebeau (TeamB)
Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 12:17 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Patrick wrote:

I guess that I was concerned about deploying binaries containing
UI forms and dialogs in an OS that doesn't support them.

TService does not have any UI Form in it. It only has a popup dialog, but
only when (un)installing the service on the command-line (and you can disable
that dialog usin the '/silent' command-line switch).

Don't be confused by the fact that the SvcMgr unit has a dependency on the
VCL's Forms and Dialogs unit. That is a different issue.

I would prefer to keep the size low

Then you will have to resort to using the Win32 API directly, and not the
TService wrapper at all.

Do you foresee calling Application.ProcessMessages for example
to cause any problem?

There is no need to call that at all in a service. TService runs in a worker
thread that has its own message loop.

--
Remy Lebeau (TeamB)

Great, thanks again Remy,
I will give it a try.

Patrick

Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 12:22 AM   in response to: Patrick Charles in response to: Patrick Charles
Is there a way to write services in Delphi 10 Seattle in a way
that would not rely on the VCL at all?
The idea is to be able to run these services on Windows Server
Core and eventually on Windows Nano Server.

My experience is you can mostly run GUI applications as a service,
provided the application does not attempt to interact with the user
which would cause it to wait for ever. The Windows service
environment simply ignores all attempts to write to the screen.

I've got several commercial applications that run interactively or can
be installed as a Windows Service, and they just work, and have done
for 15 years. The only exception is if I use one particular third
party visual component library, which probably uses hooks that cause
the application to lock.

I'll build a Windows Nano server VM next week to test they still work.

Angus
Patrick Charles

Posts: 13
Registered: 7/13/99
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 4:33 AM   in response to: Angus Robertson in response to: Angus Robertson
Angus Robertson wrote:
Is there a way to write services in Delphi 10 Seattle in a way
that would not rely on the VCL at all?
The idea is to be able to run these services on Windows Server
Core and eventually on Windows Nano Server.

My experience is you can mostly run GUI applications as a service,
provided the application does not attempt to interact with the user
which would cause it to wait for ever. The Windows service
environment simply ignores all attempts to write to the screen.

I've got several commercial applications that run interactively or can
be installed as a Windows Service, and they just work, and have done
for 15 years. The only exception is if I use one particular third
party visual component library, which probably uses hooks that cause
the application to lock.

I'll build a Windows Nano server VM next week to test they still work.

Angus

Thank you for the response Angus,

I never wrote a service popping up a dialog or a message box either.
I use the event logs to log messages, nobody is logged on the servers.
Thank you for building a Windows Nano server VM and giving it a try.
I will wait to see what you found out.

Patrick
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 11:59 AM   in response to: Patrick Charles in response to: Patrick Charles
Patrick wrote:

I never wrote a service popping up a dialog or a message box either.

Nor should you, though it CAN be done. For message boxes, the Win32 API MessageBox()
function has a specific flag for this exact purpose, or you can use WTSSendMessage()
instead. But a dialog should not be displayed directly, it should be delegated
to a separate non-service GUI process.

I use the event logs to log messages

That is what you should be doing.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 30, 2017 11:57 AM   in response to: Angus Robertson in response to: Angus Robertson
Angus wrote:

My experience is you can mostly run GUI applications as a service,
provided the application does not attempt to interact with the user
which would cause it to wait for ever.

Right, because services are run in a non-interactive session, so there is
no monitor connected to it. Any UI a service wants to display must be displayed
in an interactive session. Typically that involves using WTSEnumerateSessions()
to find an interactive session, and then CreateProcessAsUser() to run a separate
GUI process within that session.

The Windows service environment simply ignores all attempts to write to
the screen.

Not true. The service session is still a session like any other. It CAN
create UI elements, and even "display" them (from the Win32 API's perspective),
you just won't see them on your PC monitor.

I've got several commercial applications that run interactively or can
be installed as a Windows Service, and they just work, and have done
for 15 years.

That does not mean they are run as GUI processes within the service environment.
Many apps actually use the SCM API (like they should be) when installed
as a service. That requires a whole different set of coding to handle, but
it is not very difficult to write an EXE that detects when it is being run
as a service vs a GUI and invoke the approproate set of APIs.

--
Remy Lebeau (TeamB)
Angus Robertson

Posts: 205
Registered: 3/17/00
Re: Service with no UI  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 31, 2017 12:45 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
That does not mean they are run as GUI processes within the
service environment. Many apps actually use the SCM API (like
they should be) when installed as a service.

Actually it does, 15 years ago I wrote a small 'Service Starter'
application that handles all the service control interaction, and runs
a normal GUI application, sending a windows message to it when SCM says
it should close. And that application still works nicely in Windows
2016.

Microsoft has a similar service run tool in the Windows NT toolkit.

More recent applications use the SvCom framework.

Angus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02