473,888 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6029
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******** ******@TK2MSFTN GP15.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*****@bukowo nen.nl> wrote in message
news:OJ******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP15.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*****@bukowo nen.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.d e/group/microsoft.publi c.dotnet.framew ork.windowsform s/browse_thread/thread/567c25809275e37 d/0623992bffb0499 3>

--
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*****@bukowo nen.nl> wrote in message
news:OJ******** ******@TK2MSFTN GP14.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******** ******@tk2msftn gp13.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******** *******@TK2MSFT NGP15.phx.gbl.. .
I was going by the email address.

"Rotzooi" <ro*****@bukowo nen.nl> wrote in message
news:OJ******** ******@TK2MSFTN GP14.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******** ******@tk2msftn gp13.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.ServiceP rocess.ServiceC ontroller in the config.exe to
monitor if the service is running, as well as start, stop & pause the
service. You can use ServiceBase.OnC ustomCommand &
ServiceControll er.ExecuteComma nd 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 ServiceControll er 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.Manageme nt 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.Diagnost ics.EventLog & System.Diagnost ics.Performance Counter.

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.Channe ls.Ipc.IpcChann el for .NET remoting that is
local machine only, plus System.Net.Secu rity.NegotiateS tream to secure
Remoting across machines.
FWIW: When restarting a service I use a routine similar to:

Public Shared Sub RestartService( ByVal controller As ServiceControll er)
controller.Stop ()
controller.Wait ForStatus(Servi ceControllerSta tus.Stopped)
controller.Star t()
End Sub
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rotzooi" <ro*****@bukowo nen.nl> wrote in message
news:OB******** ******@TK2MSFTN GP12.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******** *******@TK2MSFT NGP15.phx.gbl.. .
| >I was going by the email address.
| >
| > "Rotzooi" <ro*****@bukowo nen.nl> wrote in message
| > news:OJ******** ******@TK2MSFTN GP14.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******** ******@tk2msftn gp13.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******** *****@TK2MSFTNG P09.phx.gbl...
Jeroen,
Is the communication one way or two way?

You can use System.ServiceP rocess.ServiceC ontroller in the config.exe to
monitor if the service is running, as well as start, stop & pause the
service. You can use ServiceBase.OnC ustomCommand &
ServiceControll er.ExecuteComma nd 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 ServiceControll er 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.Manageme nt 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.Diagnost ics.EventLog & System.Diagnost ics.Performance Counter.

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.Channe ls.Ipc.IpcChann el for .NET remoting that is
local machine only, plus System.Net.Secu rity.NegotiateS tream to secure
Remoting across machines.
FWIW: When restarting a service I use a routine similar to:

Public Shared Sub RestartService( ByVal controller As ServiceControll er)
controller.Stop ()
controller.Wait ForStatus(Servi ceControllerSta tus.Stopped)
controller.Star t()
End Sub
--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rotzooi" <ro*****@bukowo nen.nl> wrote in message
news:OB******** ******@TK2MSFTN GP12.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******** *******@TK2MSFT NGP15.phx.gbl.. .
| >I was going by the email address.
| >
| > "Rotzooi" <ro*****@bukowo nen.nl> wrote in message
| > news:OJ******** ******@TK2MSFTN GP14.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******** ******@tk2msftn gp13.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
10336
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
1574
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 mysql service running from services viewer in win xp. I now have to manually start mysql server each time I reboot. Can someone please tell me how I can Re-set mysql to run as a service?? Or, if I re-install mysql, will it retain the db's already...
6
9926
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 systray icon? please give direction... thx
4
491
by: mario | last post by:
How to put an application in systray with F1 or any shortcut button?
3
2118
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 the csharp group), so I know that this is an issues for others as well. Does anyone know how to capture the Windows Exit/Shutdown event?
8
2692
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 install 2. Have the service interact with the SysTray In my ProjectInstaller.vb Private Sub ServiceInstaller1_AfterInstall(ByVal sender As
2
1896
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 check it every2 seconds?) i need to open another application thru command prompt and pass the parametes of the DB and alert the user. how this can be done?
4
2136
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 to the C code I've written before for Windows. It would be a small irritation to have to integrate its event loop with whichever GUI framework I'm using for the rest of it though. I don't know how to make a systray under KDE/Gnome though, but...
0
11182
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
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
10886
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,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
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
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3252
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.