473,406 Members | 2,633 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,406 software developers and data experts.

Difficulties getting notification Icon to work with a Service

hello Gentlemen,

been trying to get a shell program working where I have a Windows
service that also has a Notification icon in the system tray.....

I got this idea from microsofts Visual Basic .Net cookbook, but cannot
seem to get it to work.
Also I am using the Visual Studio 2005 not 2003 as original book was I
believe created for.
and I added an icon resource into the project also. You can add your
own of course, just call it app.ico or change the code acordingly I
would assume.

here is the code.... I added line continuation Underscores for
readability within the google group, not for actual code
processing....... any comments will help.
Imports System.ServiceProcess
Imports System.Timers
Imports Microsoft.Win32
Imports System.Drawing
Imports System.Windows.Forms
Public Class TimerService
Inherits System.ServiceProcess.ServiceBase

#Region " Component Designer generated code "

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call

End Sub

' The main entry point for the process
<MTAThread()_
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
TimerService()}

System.ServiceProcess.ServiceBase.Run(ServicesToRu n)

End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer
Private thisContextMenu As System.Windows.Forms.ContextMenu
Friend WithEvents thisMenuItem As System.Windows.Forms.MenuItem
Friend WithEvents thisServiceicon As
System.Windows.Forms.NotifyIcon

' NOTE: The following procedure is required by the Component
Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()

me.components = New System.ComponentModel.Container()
Me.thisContextMenu = New System.Windows.Forms.ContextMenu
Me.thisMenuItem = New System.Windows.Forms.MenuItem

' Initialize contextMenu1
Me.thisMenuItem.Text = "E&xit"
Me.thisContextMenu.MenuItems.Add(0,Me.thisMenuItem )

Dim resources As System.Resources.ResourceManager = New _

System.Resources.ResourceManager(GetType(TimerServ ice))
Me.thisServiceicon = New
System.Windows.Forms.NotifyIcon(Me.components)

' thisServiceicon
Me.thisServiceicon.Icon =
CType(resources.GetObject("app.Icon"), System.Drawing.Icon)
Me.thisServiceicon.ContextMenu = Me.thisContextMenu

Me.thisServiceicon.Text = "Initialize"
Me.thisServiceicon.BalloonTipText = "Timer Service"
Me.thisServiceicon.BalloonTipTitle = "Timer Service"
Me.thisServiceicon.Visible = True

Me.ServiceName = "TimerService"

End Sub

#End Region

' This fires every 10 seconds.
Private WithEvents ServiceTimer As New Timers.Timer(10000)
Private Counter As Integer

Protected Overrides Sub OnStart(ByVal args() As String)

ServiceTimer.Start()
me.AutoLog = True

Me.thisServiceicon.ShowBalloonTip(1, "Started " +
TimerService.APP_TITLE , _
"You can double click on this icon
to configure settings.\nClick _
here if you do not wish to see this
message again.", CType(1, _
Windows.Forms.ToolTipIcon))

End Sub

Protected Overrides Sub OnStop()
ServiceTimer.Stop()

End Sub

Private Sub DoWork(ByVal sender As Object, ByVal e As
ElapsedEventArgs) Handles ServiceTimer.Elapsed

Dim myFile As New System.IO.FileStream("c:\ServiceTest.txt",
IO.FileMode.Append )
Dim myStream As New system.IO.StreamWriter(myFile)

Counter += 1
'Debug.WriteLine("Repetition #" & Counter.ToString())

Try
myStream.Write("Test #" & Counter.ToString() & vbCRLF)

Me.EventLog.Source = "TimerService"
Diagnostics.EventLog.WriteEntry("TimerService","Re petition
#" & _
Counter.ToString
(),EventLogEntryType.Information,5000,1)
Diagnostics.EventLog.WriteEntry("TimerService","Is visible?
" & _

Me.thisServiceicon.Visible,EventLogEntryType.Infor mation,5000,1)

Catch Ex As Exception
Debug.WriteLine(Ex.ToString())

Finally
myStream.Flush()
myFile.Close()

End Try

End Sub

Private Sub thisServiceicon_DoubleClick(Sender as object, e as
EventArgs) _
handles thisServiceicon.DoubleClick
' Show the selected item when the user double clicks on the
notify icon.
end sub

Private Sub thisMenuItem_Click(Sender as object, e as EventArgs)
handles thisMenuItem.Click
' Close the service.
me.OnStop

end sub

End Class

Jan 23 '07 #1
7 3972

Forgot to tell you what the problem is!!! :)

The icon will not appear for me.....
I register it with the INSTALLUTIL executable for .Net 2.0
the event log gets written too and the text file too.

but no icon! :(
Brian wrote:
hello Gentlemen,
Jan 23 '07 #2
"Brian" <ha******@ix.netcom.comschrieb
hello Gentlemen,

been trying to get a shell program working where I have a Windows
service that also has a Notification icon in the system tray.....

I got this idea from microsofts Visual Basic .Net cookbook, but
cannot seem to get it to work.
Doesn't work means what? Compilation error? Runtime excpetion? Wrong
behavior?

In general: Service <UI. If you want to do it, you must allow the service
to "interact with desktop". See 2nd folder in the service property window in
service manager.
Armin

Jan 23 '07 #3
Armin Zingler wrote:
"Brian" <ha******@ix.netcom.comschrieb
hello Gentlemen,

been trying to get a shell program working where I have a Windows
service that also has a Notification icon in the system tray.....

I got this idea from microsofts Visual Basic .Net cookbook, but
cannot seem to get it to work.

Doesn't work means what? Compilation error? Runtime excpetion? Wrong
behavior?

In general: Service <UI. If you want to do it, you must allow the service
to "interact with desktop". See 2nd folder in the service property window in
service manager.
And note that this will no longer work under Windows Vista. Making a
service interact with the desktop is discouraged. The recommended
approach is to create a second program that communicates with the
service and displays the icon.

Chris

Jan 23 '07 #4

Armin Zingler wrote:
". See 2nd folder in the service property window in
service manager."
Armin
Not sure what that means...
Yes gentlemen i am aware this is not a sugested means for a solution,
just thought since Microsoft Press printed this possibility in their
Cookbook then it should at least work once.....

any other suggestion?

~Brian

Jan 23 '07 #5
"Brian" <ha******@ix.netcom.comschrieb
>
Armin Zingler wrote:
". See 2nd folder in the service property window in
service manager."
Armin

Not sure what that means...
Yes gentlemen i am aware this is not a sugested means for a
solution, just thought since Microsoft Press printed this
possibility in their Cookbook then it should at least work once.....

any other suggestion?

Does this mean you have already enabled this option and it still doesn't
work? If you have, I have no other suggestion.
Armin

Jan 23 '07 #6

Armin Zingler wrote:
Does this mean you have already enabled this option and it still doesn't
work? If you have, I have no other suggestion.

Armin
I do not see a property for 'Interact with Desktop' in my Visual Studio
2005 interface, can oyu give me a little more advice on where this
feature is at?

thanks

~Brian

Jan 23 '07 #7
"Brian" <ha******@ix.netcom.comschrieb
>
Armin Zingler wrote:
Does this mean you have already enabled this option and it still
doesn't work? If you have, I have no other suggestion.

Armin

I do not see a property for 'Interact with Desktop' in my Visual
Studio 2005 interface, can oyu give me a little more advice on where
this feature is at?

quote: "...in service manager"

Start menu - run: services.msc
open service properties, 2nd tab page, check "interact with desktop" (or
similar text)
Armin

Jan 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kelly C | last post by:
Alright, I'm trying to change my application icon without setting the icon property of every form. I've replaced the App.ico file in the project dir with a new icon. When i compile and run my...
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: utkarsh | last post by:
Hi, I want to develop a Window Service in C# that should be capable of sisplaying the a icon in the window tray. Based on some logic in service, icon should be changed to some other...
2
by: Randall Powell | last post by:
I am in the process of developing a Windows Service which will: (1) monitor multiple network shares; (2) marshal text file transfers into an SQL Server 2000 instance; and (3) provide messaging...
0
by: kapcreations | last post by:
I have a system tray app which gets the status of a windows service, and displays the appropriate icon for the status of the service in the systray. the problem I am having is the icon disapears...
0
by: Eric | last post by:
Hi, For my program I use the notification control to show the user at least an icon or if (s)he decides to, a balloon as wel with some info. In the balloon I have two linkbuttons en the problem...
1
by: =?Utf-8?B?UmFmaQ==?= | last post by:
Hi, I made a 'windows services' which works well. When I added a notificaton icon, the icon apeared in the tray bar but when I clicked it, no events came into my service. (I did allowed the...
5
by: kimiraikkonen | last post by:
Hi, I was working on a screen capturing application which must do its work when a key (eg: CTRL) is pressed while the application is resides in tray as a notification icon. I mean, while my...
3
by: MarkS | last post by:
Is there any way to get rid of that ugly blown-up blue window icon that appears on all of my VB.net executables? I would rather just have the system's default application icon, like in C# and C++....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.