473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating a Service with Systray icon

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
9 5978
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
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
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
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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lalit | last post by:
Hi Friends, I have developed a Windows service. Now i need icon for this service in systray and context menu fo this icon. Can i do this? With regards, Lalit
4
by: wink martindale | last post by:
Hello, I installed mysql server 4.1 last month. When I installed it, I set it to run as a service to start automatically. However, for some reason, that no longer occurs. I can't even see the...
6
by: Action | last post by:
I can add a systray icon in normal windows application... but when i do it in windows service, the systray icon just don't show up is that because i don't have any "component" to contain the...
4
by: mario | last post by:
How to put an application in systray with F1 or any shortcut button?
3
by: Erik Greene | last post by:
I have written an application that contains a notifyicon that will not dispose or end when Windows shutsdown. I have seen other posts where people are experiencing the same issue (see post in...
8
by: Rob R. Ainscough | last post by:
I have a VS 2005 Windows Service with a Installer project as part of my solution. The Service installs fine but I can't seem to make either of these work: 1. Have the service start after...
2
by: Arvi | last post by:
Hello, Im quite new to c# windows application. i need to write a application which stays on the systray and listens to the SQL Table. (when the value is inserted as 0 - done thru Dataset and...
4
by: Nick Craig-Wood | last post by:
Does anyone have some hints / tips / experience with making a cross platform systray icon? It should work on Windows, Gnome and KDE at minimum. I've seen the win32all code which is very similar...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.