469,649 Members | 1,709 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Windows service with icon on taskbar

I've developed a windows service that monitors the database and shows
icon of a different color depending on the data. To be able to show an
icon I have to select the "Allow service to interact with desktop"
checkbox on the service, and when I do it manually, the icon shows just
fine.

But I want the users to double-click the installation file and not have
to go to the Services and select the checkbox. So I used this example
http://www.codeproject.com/csharp/Cs...iceDesktop.asp to check
the checkbox programmatically. I found out that it selected the
checkbox, but the icon still doesn't show. But if I go and manually
deselect and select the checkbox, it starts working. So I figured that
piece of code in the example does select the checkbox, but does not
really change the property of the service.

I also tried this:
ServiceController sc = new ServiceController("MyServiceName");
sc.ServiceType = ServiceType.InteractiveProcess;

but got an error message:
Property or indexer
'System.ServiceProcess.ServiceController.ServiceTy pe' cannot be
assigned to -- it is read only.

So I am wondering if there is any way to allow a service to interact
with desktop programmatically. Would appreciate any help.

Jul 18 '06 #1
4 15211
Julia,

The article that you referenced should be disregarded.

Services should never be set to interact with the desktop. You can not
always assume that there is an interactive user session to work with.

What you should do is have your service expose a remoting endpoint, and
then have an application that runs in the tray that makes calls to the
service through remoting to get/set information and receive feedback.

You can then have this program run on startup so that it is launched
when a user logs in.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ju*******@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
I've developed a windows service that monitors the database and shows
icon of a different color depending on the data. To be able to show an
icon I have to select the "Allow service to interact with desktop"
checkbox on the service, and when I do it manually, the icon shows just
fine.

But I want the users to double-click the installation file and not have
to go to the Services and select the checkbox. So I used this example
http://www.codeproject.com/csharp/Cs...iceDesktop.asp to check
the checkbox programmatically. I found out that it selected the
checkbox, but the icon still doesn't show. But if I go and manually
deselect and select the checkbox, it starts working. So I figured that
piece of code in the example does select the checkbox, but does not
really change the property of the service.

I also tried this:
ServiceController sc = new ServiceController("MyServiceName");
sc.ServiceType = ServiceType.InteractiveProcess;

but got an error message:
Property or indexer
'System.ServiceProcess.ServiceController.ServiceTy pe' cannot be
assigned to -- it is read only.

So I am wondering if there is any way to allow a service to interact
with desktop programmatically. Would appreciate any help.

Jul 18 '06 #2
Hello ju*******@gmail.com,

The whole approach is wrong. You should avoid comunication with desktom from
the service.
Service and UI are 2 different things. Service started before user logon
and works in the different security context.

Moreover, in the Windows Vista you have no access to the "Allow service to
interact with desktop" at all.

You need to use some IPC approach to interact with your service from UI.
You can use Pipes, Sockets, Remoting, SOAP, DCOM - everything that suitable
in your case
I've developed a windows service that monitors the database and shows
icon of a different color depending on the data. To be able to show an
icon I have to select the "Allow service to interact with desktop"
checkbox on the service, and when I do it manually, the icon shows
just fine.

But I want the users to double-click the installation file and not
have to go to the Services and select the checkbox. So I used this
example http://www.codeproject.com/csharp/Cs...iceDesktop.asp
to check the checkbox programmatically. I found out that it selected
the checkbox, but the icon still doesn't show. But if I go and
manually deselect and select the checkbox, it starts working. So I
figured that piece of code in the example does select the checkbox,
but does not really change the property of the service.

I also tried this:
ServiceController sc = new ServiceController("MyServiceName");
sc.ServiceType = ServiceType.InteractiveProcess;
but got an error message:
Property or indexer
'System.ServiceProcess.ServiceController.ServiceTy pe' cannot be
assigned to -- it is read only.
So I am wondering if there is any way to allow a service to interact
with desktop programmatically. Would appreciate any help.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 18 '06 #3
Thanks for quick reply, guys.

Ok, I guess my whole approach is wrong. It doesn't have to be a
service. What I need is some kind of program that starts when a user
logs in, it should run in the background and check the database once in
a while. When a certain data appears in the database, an icon on a
taskbar should change. So what is the easiest way to do it?

Jul 18 '06 #4
Hello ju*******@gmail.com,
Thanks for quick reply, guys.

Ok, I guess my whole approach is wrong. It doesn't have to be a
service. What I need is some kind of program that starts when a user
logs in, it should run in the background and check the database once
in a while. When a certain data appears in the database, an icon on a
taskbar should change. So what is the easiest way to do it?
Any app that will start from the Autorun folder

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rob Y | last post: by
2 posts views Thread by Brian | last post: by
2 posts views Thread by flaper87 | last post: by
2 posts views Thread by Robert McEuen | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.