473,796 Members | 2,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service in VB

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
4 3115
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

"SimpTheChi mp" <Si**********@d iscussions.micr osoft.com> escribió en el
mensaje news:6E******** *************** ***********@mic rosoft.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
"SimpTheChi mp" <Si**********@d iscussions.micr osoft.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=%24 9uYzKMtEHA.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
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:
"SimpTheChi mp" <Si**********@d iscussions.micr osoft.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=%24 9uYzKMtEHA.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
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 MarshalByRefObj ect. 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
NotificationIco n 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.GetOb ject 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.

"SimpTheChi mp" <Si**********@d iscussions.micr osoft.com> wrote in message
news:CA******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2267
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
5691
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the service System.ServiceProcess.ServiceBase don't catchWindows messages like mouse or timer messages. Any Idea? Thanks,
9
7273
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
1
3454
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
0
3942
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server - Select from two specific services - Check the status of the server
3
3691
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with no problems. However, I am not able to start or stop the service unless I go through the process of impersonating an administrative user. (See MSDN KB 306158) Since it appears to be a privilege issue, I set the folders in IIS holding the Web...
2
6903
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
4
4185
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
5
3310
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
1
2089
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding, endpoint etc. programmatically in the Program.cs file. Any idea what I might be doing wrong? Cheers,
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.