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

Creating a Service with Systray icon

P: n/a
Hi,

I have a VB.NET Service application that's running fine under the Local
System account. But for configuration purposes I don't want to be dependent
on modifying the registry manually or using an seperate application (like I
do now).

I want to implement a system tray icon when someone logs on to the console.
I've tried several samples but I can't get the icon to the system tray. I
know there are some issues because the logged on account differs from the
Local System account, and if no one is logged on to the console there is no
shell with a system tray.

How can I create a system tray icon when the shell is active? And one step
more: how can I detect if the shell is started from a Terminal Server
session or from the console?
Jeroen.
Dec 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Rotzooi wrote:
Hi,

I have a VB.NET Service application that's running fine under the Local
System account. But for configuration purposes I don't want to be dependent
on modifying the registry manually or using an seperate application (like I
do now).

I want to implement a system tray icon when someone logs on to the console.
I've tried several samples but I can't get the icon to the system tray. I
know there are some issues because the logged on account differs from the
Local System account, and if no one is logged on to the console there is no
shell with a system tray.

How can I create a system tray icon when the shell is active? And one step
more: how can I detect if the shell is started from a Terminal Server
session or from the console?
Jeroen.


You won't (easily) get a windows service to have a system tray icon
since services aren't ment to have a UI. You have to write a seperate
program that goes to the systray and have that program intract with your
service in some way.

Chris
Dec 15 '05 #2

P: n/a
I disagree with that. I have several other programs that are single .exe
files and run as a service, but show an icon in the systemtray when the
console (or RDP client) is logged on. If using two seperate applications
(one service, one configuration tool), how can I parse realtime variables
from one to another? And there must be a way to detect that the shell is
started to start the systray application without using the Run-key in the
registry (like some virusscanners do).

Jeroen

"Chris" <no@spam.com> schreef in bericht
news:ud**************@TK2MSFTNGP15.phx.gbl...
Rotzooi wrote:
Hi,

I have a VB.NET Service application that's running fine under the Local
System account. But for configuration purposes I don't want to be
dependent on modifying the registry manually or using an seperate
application (like I do now).

I want to implement a system tray icon when someone logs on to the
console. I've tried several samples but I can't get the icon to the
system tray. I know there are some issues because the logged on account
differs from the Local System account, and if no one is logged on to the
console there is no shell with a system tray.

How can I create a system tray icon when the shell is active? And one
step more: how can I detect if the shell is started from a Terminal
Server session or from the console?
Jeroen.


You won't (easily) get a windows service to have a system tray icon since
services aren't ment to have a UI. You have to write a seperate program
that goes to the systray and have that program intract with your service
in some way.

Chris

Dec 15 '05 #3

P: n/a
Rotzooi,
Although you can have a service interact with the desktop, it is strongly
recommend by MS & others that you don't!!

Due largely to security reasons!
http://msdn.microsoft.com/library/de...e_services.asp

Remember that most services run with heightened privileges, having it
interact with the desktop may allow non privileged users access to
privileged code.

For example SQL Server & its Service Manager. Two separate processes.

I use & promote using two separate applications. If the user wants to have
it (the config tool) run all the time, the user can add it to the startup
group (I don't automatically modify any of the Run keys in the registry).
Optionally my setup program could add the config tool to the users Startup
Group based on an option in the Install. With the Startup Group the user has
easy control over adding it or removing it at their leisure.

An added benefit from two separate applications is that you can install the
config tool on a separate machine & have it monitor the first machine...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rotzooi" <ro*****@bukowonen.nl> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl...
|I disagree with that. I have several other programs that are single .exe
| files and run as a service, but show an icon in the systemtray when the
| console (or RDP client) is logged on. If using two seperate applications
| (one service, one configuration tool), how can I parse realtime variables
| from one to another? And there must be a way to detect that the shell is
| started to start the systray application without using the Run-key in the
| registry (like some virusscanners do).
|
| Jeroen
|
| "Chris" <no@spam.com> schreef in bericht
| news:ud**************@TK2MSFTNGP15.phx.gbl...
| > Rotzooi wrote:
| >> Hi,
| >>
| >> I have a VB.NET Service application that's running fine under the Local
| >> System account. But for configuration purposes I don't want to be
| >> dependent on modifying the registry manually or using an seperate
| >> application (like I do now).
| >>
| >> I want to implement a system tray icon when someone logs on to the
| >> console. I've tried several samples but I can't get the icon to the
| >> system tray. I know there are some issues because the logged on account
| >> differs from the Local System account, and if no one is logged on to
the
| >> console there is no shell with a system tray.
| >>
| >> How can I create a system tray icon when the shell is active? And one
| >> step more: how can I detect if the shell is started from a Terminal
| >> Server session or from the console?
| >>
| >>
| >> Jeroen.
| >
| > You won't (easily) get a windows service to have a system tray icon
since
| > services aren't ment to have a UI. You have to write a seperate program
| > that goes to the systray and have that program intract with your service
| > in some way.
| >
| > Chris
|
|
Dec 16 '05 #4

P: n/a
Jay,
Rotzooi,


Means something as Rotten Heap in Dutch (Garbage), could not resist to tell
this to you.

His subscription was Jeroen,

:-)

Cor
Dec 16 '05 #5

P: n/a
"Rotzooi" <ro*****@bukowonen.nl> schrieb:
I have a VB.NET Service application that's running fine under the Local
System account. But for configuration purposes I don't want to be
dependent on modifying the registry manually or using an seperate
application (like I do now).


I strongly recommend to use a separate application:

<URL:http://groups.google.de/group/microsoft.public.dotnet.framework.windowsforms/browse_thread/thread/567c25809275e37d/0623992bffb04993>

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

Dec 16 '05 #6

P: n/a
I was going by the email address.

"Rotzooi" <ro*****@bukowonen.nl> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl...
|I disagree with that. I have several other programs that are single .exe
....
| Jeroen
I totally missed he signed it Jeroen...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OK**************@tk2msftngp13.phx.gbl...
| Jay,
|
| > Rotzooi,
|
| Means something as Rotten Heap in Dutch (Garbage), could not resist to
tell
| this to you.
|
| His subscription was Jeroen,
|
| :-)
|
| Cor
|
|
Dec 16 '05 #7

P: n/a
Thanks for the extra information about do's and don't's. Very usefull
(although the application doesn't do much accessing system resources).

How do I let the service and config tool communicate in real-time with
eachother? This is why I had to make this in one application. Any
suggestions or good links to such examples?
Jeroen a.k.a. Rotzooi a.k.a. Garbage

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schreef in
bericht news:%2***************@TK2MSFTNGP15.phx.gbl...
I was going by the email address.

"Rotzooi" <ro*****@bukowonen.nl> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl...
|I disagree with that. I have several other programs that are single .exe
...
| Jeroen
I totally missed he signed it Jeroen...
--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OK**************@tk2msftngp13.phx.gbl...
| Jay,
|
| > Rotzooi,
|
| Means something as Rotten Heap in Dutch (Garbage), could not resist to
tell
| this to you.
|
| His subscription was Jeroen,
|
| :-)
|
| Cor
|
|

Dec 20 '05 #8

P: n/a
Jeroen,
Is the communication one way or two way?

You can use System.ServiceProcess.ServiceController in the config.exe to
monitor if the service is running, as well as start, stop & pause the
service. You can use ServiceBase.OnCustomCommand &
ServiceController.ExecuteCommand to send custom commands to the service,
unfortunately the custom commands are limited to 128 to 255. I would
recommend using an Enum to identify the custom commands.

I've used XmlDocument in the config.exe to modify the service's app.config
file to change configuration settings, then used a ServiceController to
restart the service, so it picks up the new settings.

For richer two way communication, you can use .NET remoting.

Both of the custom commands & remoting with a service are discussed in
Matthew MacDonalds book "Microsoft Visual Basic .NET Programmer's Cookbook"
from MS Press.

You can also use WMI (Windows Management
Instrumentation) via the classes in the System.Management namespace to
monitor your windows service.

Here is an MSDN article on WMI & .NET:

http://msdn.microsoft.com/vstudio/de...ml/vs04d6a.asp

WMI also has events & custom objects for control. I consider Remoting over
WMI, unless I needed/wanted the WMI integration with Enterprise Management
tools.

In addition to/instead of WMI you can also simply use Performance Counters &
Event Logs to keep track of your service doing work. See
System.Diagnostics.EventLog & System.Diagnostics.PerformanceCounter.

Of course: You could also "roll your own" communication with Sockets or
TCP/IP clients, however .NET Remoting will safe you a lot of effort.
..NET 2.0 (VS 2005) introduces
System.Runtime.Remoting.Channels.Ipc.IpcChannel for .NET remoting that is
local machine only, plus System.Net.Security.NegotiateStream to secure
Remoting across machines.
FWIW: When restarting a service I use a routine similar to:

Public Shared Sub RestartService(ByVal controller As ServiceController)
controller.Stop()
controller.WaitForStatus(ServiceControllerStatus.S topped)
controller.Start()
End Sub
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rotzooi" <ro*****@bukowonen.nl> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
| Thanks for the extra information about do's and don't's. Very usefull
| (although the application doesn't do much accessing system resources).
|
| How do I let the service and config tool communicate in real-time with
| eachother? This is why I had to make this in one application. Any
| suggestions or good links to such examples?
|
|
| Jeroen a.k.a. Rotzooi a.k.a. Garbage
|
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schreef in
| bericht news:%2***************@TK2MSFTNGP15.phx.gbl...
| >I was going by the email address.
| >
| > "Rotzooi" <ro*****@bukowonen.nl> wrote in message
| > news:OJ**************@TK2MSFTNGP14.phx.gbl...
| > |I disagree with that. I have several other programs that are single
..exe
| > ...
| > | Jeroen
| >
| >
| > I totally missed he signed it Jeroen...
| >
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > "Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
| > news:OK**************@tk2msftngp13.phx.gbl...
| > | Jay,
| > |
| > | > Rotzooi,
| > |
| > | Means something as Rotten Heap in Dutch (Garbage), could not resist to
| > tell
| > | this to you.
| > |
| > | His subscription was Jeroen,
| > |
| > | :-)
| > |
| > | Cor
| > |
| > |
| >
| >
|
|
Dec 20 '05 #9

P: n/a
Jay,

Thanks for the many suggestions. Since my service will use both values for
monitoring and configuring, I've decided to use the socket client way.
Although this option gives me some more overhead in programming, I can set
built-in features for quick command-line/telnet monitoring. Also I can be
more flexible in monitoring and configuring the service over the internet
when installed on remote locations (set IPs for both local and trusted
remote clients, DNS and Port). But I will have a look at Remoting for my
next project.
Jeroen

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schreef in
bericht news:OK*************@TK2MSFTNGP09.phx.gbl...
Jeroen,
Is the communication one way or two way?

You can use System.ServiceProcess.ServiceController in the config.exe to
monitor if the service is running, as well as start, stop & pause the
service. You can use ServiceBase.OnCustomCommand &
ServiceController.ExecuteCommand to send custom commands to the service,
unfortunately the custom commands are limited to 128 to 255. I would
recommend using an Enum to identify the custom commands.

I've used XmlDocument in the config.exe to modify the service's app.config
file to change configuration settings, then used a ServiceController to
restart the service, so it picks up the new settings.

For richer two way communication, you can use .NET remoting.

Both of the custom commands & remoting with a service are discussed in
Matthew MacDonalds book "Microsoft Visual Basic .NET Programmer's
Cookbook"
from MS Press.

You can also use WMI (Windows Management
Instrumentation) via the classes in the System.Management namespace to
monitor your windows service.

Here is an MSDN article on WMI & .NET:

http://msdn.microsoft.com/vstudio/de...ml/vs04d6a.asp

WMI also has events & custom objects for control. I consider Remoting over
WMI, unless I needed/wanted the WMI integration with Enterprise Management
tools.

In addition to/instead of WMI you can also simply use Performance Counters
&
Event Logs to keep track of your service doing work. See
System.Diagnostics.EventLog & System.Diagnostics.PerformanceCounter.

Of course: You could also "roll your own" communication with Sockets or
TCP/IP clients, however .NET Remoting will safe you a lot of effort.
.NET 2.0 (VS 2005) introduces
System.Runtime.Remoting.Channels.Ipc.IpcChannel for .NET remoting that is
local machine only, plus System.Net.Security.NegotiateStream to secure
Remoting across machines.
FWIW: When restarting a service I use a routine similar to:

Public Shared Sub RestartService(ByVal controller As ServiceController)
controller.Stop()
controller.WaitForStatus(ServiceControllerStatus.S topped)
controller.Start()
End Sub
--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rotzooi" <ro*****@bukowonen.nl> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
| Thanks for the extra information about do's and don't's. Very usefull
| (although the application doesn't do much accessing system resources).
|
| How do I let the service and config tool communicate in real-time with
| eachother? This is why I had to make this in one application. Any
| suggestions or good links to such examples?
|
|
| Jeroen a.k.a. Rotzooi a.k.a. Garbage
|
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schreef
in
| bericht news:%2***************@TK2MSFTNGP15.phx.gbl...
| >I was going by the email address.
| >
| > "Rotzooi" <ro*****@bukowonen.nl> wrote in message
| > news:OJ**************@TK2MSFTNGP14.phx.gbl...
| > |I disagree with that. I have several other programs that are single
.exe
| > ...
| > | Jeroen
| >
| >
| > I totally missed he signed it Jeroen...
| >
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > "Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
| > news:OK**************@tk2msftngp13.phx.gbl...
| > | Jay,
| > |
| > | > Rotzooi,
| > |
| > | Means something as Rotten Heap in Dutch (Garbage), could not resist
to
| > tell
| > | this to you.
| > |
| > | His subscription was Jeroen,
| > |
| > | :-)
| > |
| > | Cor
| > |
| > |
| >
| >
|
|

Dec 28 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.