EDIT: I'm starting a bounty on this question. For the moment, I've moved on and am developing my application using VS2010 Pro Beta, but I'd really like it to be able to be built with express edition, since we are generally not a .net shop and even if one or two developers have VS PRO it will not be available to our entire team.
To be the accepted answer and claim the bounty, you must provide sample code and instructions that will allow a Windows Service to be installed and uninstalled using vb 2008 express edition. You don't necessarily need to start with my code (but the essentials of it are included below).
I've written a VB.NET application which I would like to run as a service. Currently I'm using VB.net Express Edition (2008) which does not ship with the "Service" template, but I've added a Service class (inheriting from ServiceBase) and an Installer class (inheriting from Installer); in both cases I'm following sample code from MSDN. Unfortunately I haven't been able to get this code to install and run as a service.
The meat of this code is a TCP Listener class called sampleListener. If I set the sampleListener class as the startup object and run my project, it runs fine as a console application.
There's a service class (below) which simply starts the sampleListener.
Public Class sampleSocketService
Inherits System.ServiceProcess.ServiceBase
Public Sub New()
Me.ServiceName = "sample Socket Service"
Me.CanStop = True
Me.CanPauseAndContinue = True
Me.AutoLog = True
End Sub
Shared Sub Main()
System.ServiceProcess.ServiceBase.Run(New sampleSocketService)
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
sampleListener.Main()
End Sub
End Class
There's also an installer class which I think is the source of my problems. Here's the installer class as I initially wrote it.
Imports System
Imports System.Collections
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.ComponentModel
<RunInstallerAttribute(True)> _
Public Class sampleSocketServiceInstaller
Inherits Installer
Private serviceInstaller1 As ServiceInstaller
Private processInstaller As ServiceProcessInstaller
Public Sub New()
' Instantiate installers for process and services.
processInstaller = New ServiceProcessInstaller()
serviceInstaller1 = New ServiceInstaller()
processInstaller.Account = ServiceAccount.LocalSystem
serviceInstaller1.StartType = ServiceStartMode.Automatic
' ServiceName must equal those on ServiceBase derived classes.
serviceInstaller1.ServiceName = "sample Socket Service"
' Add installers to collection. Order is not important.
Installers.Add(serviceInstaller1)
Installers.Add(processInstaller)
End Sub
End Class
Running installutil.exe on this produces the following message:
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.
This looks like a security problem, but I'm running in a cmd window that was opened using Run As Administrator.
I tried a much simplified Installer class based on an online example:
Imports System.ComponentModel
Imports System.Configuration.Install
<RunInstaller(True)> Public Class ProjectInstaller
Inherits System.Configuration.Install.Installer
End Class
This seems ridiculously simple, and I couldn't figure out how it could possibly work, and in fact it didn't. However, when running installutil.exe on the project with this version of the installer class, installutil.exe does not throw an error message and reports that the service has been installed successfully.
I suspect I need code in my installer class that does some of what's in my first example, but doesn't do whichever part is causing the error.
Any suggestions?
(This has been edited extensively for clarity and to add code examples which were not originally included)