By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,394 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,394 IT Pros & Developers. It's quick & easy.

Windows Service in VB

P: n/a
I am going to write (my first) Windows Service. What I want is this service
to run automatically when the computer/server is booted.... But also, to
display an icon in the system tray whenever any user logs onto the computer
(to display status, allow preference setting for the service, etc).

I am well versed in .NET and VB.NET, but I haven't written a service before.
Just curious as to exactly how to make the service so that it not only does
it's 'service' thing but also can display a form/system tray icon whenever a
user logs on.

Any advice/links to other code appreciated. Thanks in advance.

Tom (Chimp)
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
There are several articles out there, for example:

http://www.devcity.net/Articles/74/1...ontroller.aspx

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"SimpTheChimp" <Si**********@discussions.microsoft.com> escribió en el
mensaje news:6E**********************************@microsof t.com...
I am going to write (my first) Windows Service. What I want is this service
to run automatically when the computer/server is booted.... But also, to
display an icon in the system tray whenever any user logs onto the
computer
(to display status, allow preference setting for the service, etc).

I am well versed in .NET and VB.NET, but I haven't written a service
before.
Just curious as to exactly how to make the service so that it not only
does
it's 'service' thing but also can display a form/system tray icon whenever
a
user logs on.

Any advice/links to other code appreciated. Thanks in advance.

Tom (Chimp)

Nov 21 '05 #2

P: n/a
"SimpTheChimp" <Si**********@discussions.microsoft.com> schrieb:
I am going to write (my first) Windows Service. What I want is this service
to run automatically when the computer/server is booted.... But also, to
display an icon in the system tray whenever any user logs onto the
computer
(to display status, allow preference setting for the service, etc).


<URL:http://www.google.es/groups?selm=%249uYzKMtEHA.2896%40cpmsftngxa06.phx. gbl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
Hey all! Thanks for the info.... one question still remains, though, as I
looked all this over: I seen how I can communicate things INTO the service
(by using the custom command thingy) but how do I get custom info OUT of the
service (other than the base things). Maybe, for instance, I want my UI to be
able to query the service to see exactly what it is doing at this time (i.e.,
if it is processing a record - which record? Or if it is processing a file -
which file?) Since, from what I understand, a service doesn't support public
interfaces, how would one go about getting this kind of custom info from a
service?

Tom (Chimp)

"Herfried K. Wagner [MVP]" wrote:
"SimpTheChimp" <Si**********@discussions.microsoft.com> schrieb:
I am going to write (my first) Windows Service. What I want is this service
to run automatically when the computer/server is booted.... But also, to
display an icon in the system tray whenever any user logs onto the
computer
(to display status, allow preference setting for the service, etc).


<URL:http://www.google.es/groups?selm=%249uYzKMtEHA.2896%40cpmsftngxa06.phx. gbl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
Tom,

Your service needs to expose an interface via .Net remoting. This involves
architecting your service using two projects: a main program (either
WinForms or console) and a class library. The class library must contain a
public class that inherits from MarshalByRefObject. You need to add code to
the main program to register a TCP channel with the .Net remoting
architecture, and register the public class as a well-known singleton.

You also need to create a WinForms app that can be run by logged-in users.
This app communicates with the user via a menu attached to a
NotificationIcon object. This app communicates with your service via the
remoted class exposed by the service (above). You would set up this app so
that it runs automagically when the user logs in.

FYI, if your client app just wants to call methods on the service's remoted
interface then the client doesn't need to register a TCP channel; it just
needs to call Activator.GetObject to get a reference to the remoted
singleton. However, if you want to handle events from the remoted object
then you need to jump through some significant, not-very-well-documented
hoops:

1. Your client needs to register a TCP channel (port 0, which allocates an
unused port, will suffice). This is because the event callback looks like a
method invocation to the remoting architecture; thus, the singleton needs to
be able to call a method on the client, so the client needs a TCP channel to
receive the method invocation request.

2. The singleton needs to be able to access the client's metadata in order
to resolve the reference to the client's event handler. The easiest way to
accomplish this is to set up your build and deployment environments so that
the client's executable resides in the same folder as the singleton's dll.
A more elegant solution that doesn't require the singleton to know about
each of its clients involves declaring an interface in the singleton's
project that contains the event handlers, implementing the interface in each
client, and providing a method on the singleton that hooks up the events on
behalf of the client.

"SimpTheChimp" <Si**********@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Hey all! Thanks for the info.... one question still remains, though, as I
looked all this over: I seen how I can communicate things INTO the service
(by using the custom command thingy) but how do I get custom info OUT of the service (other than the base things). Maybe, for instance, I want my UI to be able to query the service to see exactly what it is doing at this time (i.e., if it is processing a record - which record? Or if it is processing a file - which file?) Since, from what I understand, a service doesn't support public interfaces, how would one go about getting this kind of custom info from a
service?

Tom (Chimp)

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.