Service Interaction with SysTray problem...

  • Thread starter Rob R. Ainscough
  • Start date
R

Rob R. Ainscough

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
System.Object, ByVal e As System.Configuration.Install.InstallEventArgs)
Handles ServiceInstaller1.AfterInstall

Dim OS_EventLog As New MyStuff.Utilities.OperatingSystem

Try

Dim KeyPath As String = "SYSTEM\CurrentControlSet\Services\" &
Me.ServiceInstaller1.ServiceName
Dim ckey As RegistryKey =
Registry.LocalMachine.OpenSubKey(KeyPath, True)

If ckey IsNot Nothing Then
ckey.SetValue("Type", CInt(272))
End If

Catch ex As Exception

OS_EventLog.CreateEventLogEntry("After Install Failed: " &
ex.ToString)

End Try

End Sub

This code works in the sense that the "Interacts with Desktop" checkbox IS
checked, but I still don't see my icon show in the systray. If I manually
go to my installed service and uncheck and then recheck and then start the
service again -- my icon WILL show in the systray. Is there more than one
reg entry to be set to make this work? Any hints or links where I can go to
make this do the above two tasks work reliably?

Thanks, Rob.
 
C

Chris Dunaway

Generally speaking, a service should not interact with the desktop.
You should write a "monitoring app" that communicates with the service
and that app would show your icon in the system tray. But, to
accomplish what you want, you will have to use the
System.ServiceProcess.ServiceController to set the ServiceType property
using the InteractiveService flag.

Since the service will start when the OS starts, no one will be logged
on at the time and there will be no desktop system tray to place the
icon on. How does your service know when someone has logged on?

If you intend your application to run on Windows Vista, then you cannot
allow the service to interact with the desktop as that won't be allowed
in Vista, so that's another reason not to do it in that manner.
 
R

Rob R. Ainscough

If this is implemented due to security weakness in Vista, then I'd think
Microsoft need to address the issue rather than just apply blanket
restriction to valid uses of "Interact with Desktop" option currently
available to all services.

I seriously doubt Microsoft will remove the ability to "Interact with
Desktop" for the final release of Vista. I don't think Vista is even in
"release candidate" form yet anyway. Not to mention there is a long list of
main stream apps that have services that interact with the Desktop.

What exactly is a "monitoring app"? I mean you've basically just defined
what a service is, most services are monitoring/listeners sooo...
 
G

Greg Young

He means a normal application that represents the GUI aspects of the windows
service that in turn interacts with the windows service through another
means (such as remoting).
 
R

Rob R. Ainscough

Greg,

My service doesn't provide a "UI" in the sense that a user (or any user) can
interact with it. What I want to accomplish is simply provide the user with
some indication that a critical service they need is working or not (and
perhaps a message as to why not) -- if the service is not functioning (aka
some exception) the icon in the systray changes along with a message that
appears when they hover over the icon with the mouse cursor.

If this is Microsoft's stand, then they are getting lazy once again.
Blanket solutions to security problems limits functionality -- who wants to
live in a house with bars on the all the doors and windows which can't be
opened -- who's the real prisoner? MS need to do some work if they want to
get this implemented correctly rather than saying "you just can't do that
now because of our poor security model".

But thanks for the other link -- it worked well for me, looks like was using
the wrong event.

Rob.
 
C

Chris Dunaway

Rob said:
If this is implemented due to security weakness in Vista, then I'd think

I don't know their reasons, but security was mentioned. Look for
"Windows Services Hardening". That might provide some additional
information.
What exactly is a "monitoring app"? I mean you've basically just defined
what a service is, most services are monitoring/listeners sooo...

I just meant a GUI app that runs when the user logs on that then
communicates to the service. It would be this app that puts your icon
in the tray.

When the Windows Service starts, there is no system tray to place an
icon in, at least not until the user logs on. So your service will
have to somehow detect when a user logs on in order to place the icon
in that user's system tray. And what happens if someone at the machine
uses the "Switch User" feature, your service will have to be able to
detect that as well.

In any case, as I said earlier, you can use the
System.ServiceProcess.ServiceController class to set that option. I
think it should work in your After_Install event as well.

Good luck
 
R

Rob R. Ainscough

Greg/Chris,

Thanks for the responses -- I was able to make it work under any account
using the Committing event.

Like I said before, the UI part of my service doesn't really qualify as a
GUI -- my service just changes the icon image and the hover over message and
that is it -- it doesn't actually let the user do any, just informs the user
what it is currently doing -- one should not have to write two applications
to perform this task just because of an OS weakness. I guess I'm just
getting a little concern that MS just keep dumping on developers rather than
trying to actually make our life easier, they introduce worky solutions -- I
don't see how this is a good thing.

I realize there is some nasty spyware/adware/virus out there that can and
does take advantage of the systray, but this problem needs to be address in
a different way, lets not continue to reduce features so as to be "more
secure" -- that does no one any good and basically conceeds to the hackers
and those writing dubious software in the first place.

Rob.
 
G

Guest

Hi Rob,

You know, I read your discussion and I've got this application which is dumb
in terms of UI, but just as you do, It would ideally need an icon in the tray
to display the application current condition (e.g. paused, running okay or
running with warnings). A context menu would also be nice, so that the user
could pause and resume. Is it possible for you to share your solution ?

Thanks, Jr.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top