Running A VB.NET Application as a Windows Service

  • Thread starter Thread starter DM
  • Start date Start date
D

DM

Hi All,

I have written a server program which distributes real-time data to our
customers and is also used by our customers to redistribute this data over
their internal networks. The program is just a standard Windows application
which minimizes to the systray and runs in the background.

Recently I have been asked by one of our clients whether I can make this
program run as a Windows service. After some Googling, it looks like it is
possible but it seems it would involve a major rewrite of the code.

Is there an easy way to do this?

-Duncan
 
DM said:
Hi All,

I have written a server program which distributes real-time data to
our customers and is also used by our customers to redistribute this
data over their internal networks. The program is just a standard
Windows application which minimizes to the systray and runs in the
background.
Recently I have been asked by one of our clients whether I can make
this program run as a Windows service. After some Googling, it looks
like it is possible but it seems it would involve a major rewrite of
the code.

I don't see why it should be a major re-write. There is a template for building
a windows service in VS, start with that, and add your code into it. It doesn't
sound like you have much of a GUI anyway, so it shouldn't be that big a problem.
The simplest way to drive code in a service is with a timer, and you can do most
anything in the event handler. The only real trick is to build it in a robust
way, so it can reset itself if something goes wrong, and gives up and shuts down
if something stays wrong. It also helps if it logs events or notifications
somewhere so you can check up on it.
 
Steve Gerrard said:
I don't see why it should be a major re-write. There is a template for
building a windows service in VS, start with that, and add your code into
it. It doesn't sound like you have much of a GUI anyway, so it shouldn't
be that big a problem. The simplest way to drive code in a service is with
a timer, and you can do most anything in the event handler. The only real
trick is to build it in a robust way, so it can reset itself if something
goes wrong, and gives up and shuts down if something stays wrong. It also
helps if it logs events or notifications somewhere so you can check up on
it.

I should have mentioned that I only have Visual Basic .NET 2003 standard so
no Windows service template unfortunately.

The program does have a reasonably complex GUI which allows the user to
manage client details, log network activity, set up audio & email service
alerts, track data rates etc so I'm not sure whether it's going to be that
easy.

I believe our client's problem is that they are running this application
under Windows Server 2003 and when they log on via Remote Desktop to check
the program status, then log out, it shuts the server down. Perhaps there is
another way of getting around this in the code rather than making it a
Windows service?

-Duncan
 
DM said:
I should have mentioned that I only have Visual Basic .NET 2003
standard so no Windows service template unfortunately.

I have VS 2003 at home, and it has a VB WindowsService project type, but I'm not
sure which edition it is.
The program does have a reasonably complex GUI which allows the user
to manage client details, log network activity, set up audio & email
service alerts, track data rates etc so I'm not sure whether it's
going to be that easy.

Since a service does not have a GUI, that could be a problem. :)
I believe our client's problem is that they are running this
application under Windows Server 2003 and when they log on via Remote
Desktop to check the program status, then log out, it shuts the
server down. Perhaps there is another way of getting around this in
the code rather than making it a Windows service?

I would try running the app from the Run key in the registry
(HLM\Software\Microsoft\Windows\CurrentVersion\Run). I'm not sure if that is all
it takes, but you don't want the app to run under a particular user logon, else
it will shut down when that user logs off.
 
Hi All,

I have written a server program which distributes real-time data to our
customers and is also used by our customers to redistribute this data over
their internal networks. The program is just a standard Windows application
which minimizes to the systray and runs in the background.

Recently I have been asked by one of our clients whether I can make this
program run as a Windows service. After some Googling, it looks like it is
possible but it seems it would involve a major rewrite of the code.

Is there an easy way to do this?

-Duncan

Hi,
You can modify / add / delete any correct service in that registry
entry:
[HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services]

See some existing service registry tree structure to do the same for
yours.
 
Hi,

It isn't usual/common to have a Service with a UI. However, it is possible.

I have a VB.NET 2005 example on my homepage, with an article that outlines
some of the steps, and that has links to other information. IMO, 2005 or
2008 would be a useful upgrade for your program.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Steve Gerrard said:
DM wrote: ....

I would try running the app from the Run key in the registry
(HLM\Software\Microsoft\Windows\CurrentVersion\Run). I'm not sure if that
is all it takes, but you don't want the app to run under a particular user
logon, else it will shut down when that user logs off.

Thanks I'll give this a go.

-Duncan
 
Back
Top