I asked help for a service I wrote earlier but no-one seemed to be able to help so I went back to basics and did a Windows Service tutorial from Microsoft. I followed it exactly with one exception (I added a file write to see if it was working straight away), when I ran the service it worked but when I stopped the machine and the started it didn't.
Can anyone help. Here is the code:
StartType is Automatic,
Account is LocalSystem
ServiceName in the ServiceInstaller is the same as ServiceName in the Service
Sorry the indents seem to have disappeared.
Imports System.IO
Public Class MyNewService
' To access the constructor in Visual Basic, select New from the
' method name drop-down list.
Public Sub New()
MyBase.New()
InitializeComponent()
If Not System.Diagnostics.EventLog.SourceExists("MySource") Then
System.Diagnostics.EventLog.CreateEventSource("MySource", "MyNewLog")
End If
EventLog1.Source = "MySource"
EventLog1.Log = "MyNewLog"
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
EventLog1.WriteEntry("In OnStart")
File.WriteAllText("C:\Users\Public\TestForWindows8.txt", "Test Data")
End Sub
Protected Overrides Sub OnStop()
EventLog1.WriteEntry("In OnStop.")
End Sub
End Class
Can anyone help. Here is the code:
StartType is Automatic,
Account is LocalSystem
ServiceName in the ServiceInstaller is the same as ServiceName in the Service
Sorry the indents seem to have disappeared.
Imports System.IO
Public Class MyNewService
' To access the constructor in Visual Basic, select New from the
' method name drop-down list.
Public Sub New()
MyBase.New()
InitializeComponent()
If Not System.Diagnostics.EventLog.SourceExists("MySource") Then
System.Diagnostics.EventLog.CreateEventSource("MySource", "MyNewLog")
End If
EventLog1.Source = "MySource"
EventLog1.Log = "MyNewLog"
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
EventLog1.WriteEntry("In OnStart")
File.WriteAllText("C:\Users\Public\TestForWindows8.txt", "Test Data")
End Sub
Protected Overrides Sub OnStop()
EventLog1.WriteEntry("In OnStop.")
End Sub
End Class