By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,149 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,149 IT Pros & Developers. It's quick & easy.

Windows Service Not Starting

P: n/a
I have a Windows Service I created that just sets a timer and writes to
EventLog every 10 seconds.

It installed fine and it actually starts. But it says it doesn't. The
progress bar shows the progress fine until it hits about halfway. It then
stops there for about 4 or 5 seconds then goes a little farther. I then get
a message:

Could not start the MyService Service on Local Computer.
Error 1053: The service did not respond to the Start or control request in a
timely fashion.

I look at the MyService log from Event Viewer and it is running and writing
to the Event log every 10 seconds, as it should.

But in the Services screen, it shows MyService as starting (not started) and
I can't stop it

If I try to stop it from Task Manager, I get the message:

The operation could not be completed.
Access is denied.

I have to reboot to stop it.

Here is the code:

************************************************** **************************
*****
Imports System.ServiceProcess

Public Class Service1
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

'UserService overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

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

' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase () {New
Service1}

System.ServiceProcess.ServiceBase.Run(ServicesToRu n)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

' 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.
Friend WithEvents Timer1 As System.Timers.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Timer1 = New System.Timers.Timer()
CType(Me.Timer1,
System.ComponentModel.ISupportInitialize).BeginIni t()
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10000
'
'Service1
'
Me.ServiceName = "Service1"
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).EndInit( )

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Timer1.Enabled = False
End Sub

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog()

' Check if the Event Log exists
If Not MyLog.SourceExists("MyService") Then
MyLog.CreateEventSource("MyService", "Myservice Log") ' Create
Log
End If
MyLog.Source = "MyService"
' Write to the Log
MyLog.WriteEntry("MyService Log", "This is log on " &
CStr(TimeOfDay), EventLogEntryType.Information)
End Sub
End Class
************************************************** **************************
*****

Why isn't it working correctly?

This program isn't doing much and it seems to be working fine, except for
the starting/stopping parts.

Thanks,

Tom
Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.