High-Performance Development - C#, VB, SQL, ASP.NET

Slogan Text

Problem: InstallUtil Displays Set Service Login Dialog

When you run InstallUtil tool to install a Windows service the tool displays the Set Service Login dialog requesting a username and password.

Solution: Set Account to LocalService

  1. Go to Visual Studio.
  2. Open ProjectInstaller.vb or ProjectInstaller.cs.
  3. Mouse over ServiceProcessInstaller1 and Right-click Properties.
  4. Set Account to LocalService in the Properties dialog.
  5. Rebuild the project.
  6. Attempt to install the service.

Problem: InstallUtil Displays System.Security.SecurityException

When you run InstallUtil to install your Windows service the tool displays this exception:

An exception occurred during the Install phase. System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.

Solution: Run as Administrator

Open Command Windows with Run as Administrator.

Problem: Service Does Not Start

When you run NET START <MyService> the system displays:

The service is not responding to the control function.

Solution: Potential Exception in Your Service Code

Your code might be generating an exception. Research the System Event Logs for errors:

  1. Go to Start\Control Panel.
  2. Click on System and Security.
  3. Click on Administrative Tools.
  4. Click on Event Viewer.
  5. Expand Windows Logs in left pane.
  6. Click on Application.
  7. Look for Level = Error entries.
  8. Double-click on selected entries.
  9. Review error information.

Problem: System error 1083 has occurred.

When you run InstallUtil to install your service the system displays:

System error 1083 has occurred.

The executable program that this service is configured to run in does not implement the service.

Solution 1: Service Name Must Equal Service Process Installer Service Name

In Visual Studio:

Part 1:

  1. Open your servic source code file. Example: MyService.vb.
  2. Right-click on the class name.
  3. Click Find All References.
  4. Find the statement: ServicesToRun = New System.ServiceProcess.ServiceBase() {New MyService}...
  5. Click on the code statement your found on the previous step.
  6. Visual Studio should now display MyService.Designer.VB.
  7. Find InitializeComponent method and the line: Me.ServiceName = "<MyServiceName>".
  8. Remember that service name and go to Part 2.

Part 2:

  1. Open your service source code file. Example: MyService.vb.
  2. Visual Studio should display the designer page: MyService.vb [Design].
  3. Right-click and select Properties.
  4. Scroll down to ServiceName entry.
  5. Update as needed based on the service name you found in Part 1.
  6. Rebuild project.
  7. Uninstall any previous version of your service.
  8. Install new version.

Problem: Service Could Not Be Started

You install your service with InstallUtil and thenn you attempt to start it using NET START <MyService>.

NET START displays:

The <MyService> service is starting.
The <MyService> service could not be started.
The service did not report an error.

Solution: OnStart Problems

The service OnStart and OnStop methods must return control back to the Service Control Manager within one minute for the SCM to recognize the service was successfully started or stopped.

Your OnStart or OnStop methods might be taking longer then one minute they might be generating an exception.

Part 1: Check Event Logs

Service Control Manager (SCM) might have reported errors in the Event Log.

  1. Start\Conrol Panel.
  2. Click on System and Security.
  3. Click Administrative Tools.
  4. Click Event Viewer.
  5. Look in Windows Logs\Application.

Part 2: Follow Standard Debug Process

  1. Comment all code in OnStart.
  2. Rebuild Project.
  3. Install and NET START service.
  4. Service should start.
  5. Add in one small work step to OnStart.
  6. Rebuild, Install, and NET START your service.
  7. Or, follow How to Debug Windows Service Application. See Resources below.

Part 3: Do Work in a Thread

The OnStart method should start a background thread to perform the service's work or set up a timer to fire on a regular basis to pick up work items and process them.

Problem: Failed to Stop Service

When you uninstall a service the Event Logs (Windows Logs\Application) has an entry:

Failed to stop service. System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  To create the source, you need permission to read all event logs to make sure that the new source name is unique.  Inaccessible logs: Security.

Solution: (I'm researching the solution)

 

Problem: Requested Registry Access is Not Allowed

When you attempt to start a service with NET START <MyService> this entry is in the Event Logs:

Service cannot be started. System.Security.SecurityException: Requested registry access is not allowed.

Solution:

 

Problem: InvalidOperation Exception - EventLog Source Creation

When you attempt to create a new EventLog source InstallUtil displays:

Creating EventLog source <MyService> in log Application...

An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager on compute
r '.'. This operation might require other privileges.
The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: Access is denied.

Solution:

 

Problem: The Specified Service Has Been Marked for Deletion

When trying to install a Windows Service the system displays the error:

Error 1001: The specified service has been marked for deletion.

Solution

I'm not sure which solution will solve your problem. Try them in listed order until you use one that works.

Close Services

Close the Services system application if you have it open.

SC Delete
  1. Open a Command Prompt in Administrator mode.
  2. Enter SC DELETE <MyServiceName>.
    Note: MyServiceName is not the service name displayed in the Services window.
Log Off

Log off your current session and log on.

Reboot

Reboot your system.

Successful Service Start

When NET START successfully starts your service these messages are displayed:

The <MyService> service is starting.
The <MyService> service was started successfully.

Resources

How to: Debug Windows Service Applications