How to add Systray icon when writing windows service using c#

  • Thread starter Thread starter Action
  • Start date Start date
A

Action

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
 
A service, by default anyway, does not have access to your window station,
so it also doesn't have access to your system tray. You might be able to
work aroudn this with some creative p\invoke, but it wouldn't be highly
recommended.
To do what you want to do you will need to write a seperate application that
displays the system tray icon and communicates whatever is needed with the
service.
 
You can configure the Service in Services - MMC to allow Desktop
interaction. Afterwards you can display forms, trayicons, ...

GP
 
Services MMC?
I can't find any option to allow me to do so...

and...if it can be done....can I enable it in the program rather than
manually?
coz it may not be desirable for use to enable it manually when using the
service...

Thank you
 
I saw some service able to create a systray icon
or it user other shortcuts to do so..?

thx
 
While it CAN be done, it is not advisable. There is a possiblity of
priviledge elevation via windows message attacks (I don't know if .NET helps
with that or not, but is it worth the risk?).
If you must provide the UI from the service, use the most restrictive
possible user account for the service(Definatly not SYSTEM, LocalSystem,
Administrative accounts, etc, I'd say) lest someone trys to compromise it.
Also, I doubt it is as easy as running a simple winforms application
properly across TS. Client\server really makes more sense and is more
secure, plus it is probably easier to run the client code across multiple
accounts and should allow for remote administration as well(this may not be
a prime issue now, but you may need it at some point).

these urls may be of use as well:
http://support.microsoft.com/default.aspx?scid=kb;en-us;171890
http://support.microsoft.com/default.aspx?scid=kb;en-us;308403
http://support.microsoft.com/default.aspx?scid=kb;en-us;821794
http://support.microsoft.com/default.aspx?scid=kb;en-us;327618
 
Services MMC?
I can't find any option to allow me to do so...

Open Start -> Control Panel -> Administrative Tools -> Services
Open the properties of your Service -> "Log On" --> check "Allow Service
Interaction with Desktop"

and...if it can be done....can I enable it in the program rather than
manually?
coz it may not be desirable for use to enable it manually when using the
service...

This setting is stored in the Registry under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YOUR_SERVICE_NAME
Create (or modify) a DWORD Registry Entry named "Type", and write the value
0x110 (decimal: 272) into it. Of caurse you must have the required
permission to do that. If you own them, you can do this during the
installation, or via code.

If you don't want to do this, there will be no other possibility to do this
that create another application that displays the trayicon and communicates
with your services.

mfg GP
 
Back
Top