Solved

Deploying a Windows service with a Setup Project

Posted on 2004-08-17
2
269 Views
Last Modified: 2008-01-09
Hello experts,

I know how to install a service using installutil.exe from a command prompt, but how does one deploy a service through the Setup project?  I've done Windows apps, but no services.  Please help me.  

Thanks,

Kevin
0
Comment
Question by:carmodyk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 250 total points
ID: 11820829
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q317421&ID=kb;en-us;Q317421&SD=MSDN&FR=1

Create a Setup Project for a Windows Service in Visual Basic .NET

Create a Setup Project for a Windows Service

Create a Windows Service Project
1.On the Start menu, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft
Visual Studio .NET.
2.On the File menu, point to New, and then click Project.
3.In the New Project dialog box, follow these steps:
  Under Project Types, click Visual Basic Projects.
  Under Templates, click Windows Service.
4.In the Name text box, type LogWriterService.
5.In the Location text box, type C:\, and then click OK.
6.In the Solution Explorer window, right-click Service1.vb, and then click View Code.
7.In the OnStart event handler, replace the comments with the following code:
   EventLog.WriteEntry("My simple service started.")
8.In Solution Explorer, double-click Service1.vb.
9.In the Properties dialog box, click Add Installer.
10.In the Properties dialog box for ServiceInstaller1, change the ServiceName property to LogWriterService.
11.In the Code Editor window in Design view, click ServiceProcessInstaller1.
12.In the Properties dialog box, change the Account property to LocalService.

Use a Compiled Setup Project to Install the Windows Service
After you complete the steps in the previous section to configure the Windows Service project, follow these
steps to add a deployment project that packages the service application so that the service application can
be installed:

To add a new project to your LogWriterService project, follow these steps:
1.In Solution Explorer, right-click Solution 'LogWriterService', point to Add, and then click New Project.
2.Under Project Types, click Setup and Deployment Projects.
3.Under Templates, click Setup Project.
4.In the Name text box, type ServiceSetup.
5.In the Location text box, type C:\, and then click OK.

To tell the deployment project what it should package, follow these steps:
1.In Solution Explorer, right-click ServiceSetup, point to Add, and then click Project Output.
2.In the Add Project Output Group dialog box, in the Project box, click LogWriterService.
3.Click Primary Output, and then click OK.

For proper installation, you are only required to add primary output. To add the custom actions, follow
these steps:
1.In Solution Explorer, right-click ServiceSetup, point to View, and then click Custom Actions.
2.Right-click Custom Actions, and then click Add Custom Action.
3.Click Application Folder, and then click OK.
4.Click Primary output from LogWriterService (Active), and then click OK. Notice that Primary output appears
  under Install, Commit, Rollback and Uninstall.

Setup projects are not included in the build configuration by default. To build the solution, follow these
   steps:
1.Right-click LogWriterService, and then click Build. Subsequently, right-click ServiceSetup, and then click
  Build.

-or-

Click Configuration Manager on the Build menu to build the entire solution at once. Select the Build check
box for ServiceSetup.
Press the CTRL+SHIFT+B key combination to build the entire solution. When the solution is built, you have
a complete installation package available for the service.
To install the newly built service, right-click ServiceSetup, and then click Install.
In the ServiceSetup dialog box, click Next three times. Notice that a progress bar appears while the service installs.
When the service is installed, click Close.

Complete Code Listing (Service1.vb)
Imports System.ServiceProcess

Public Class Service1
    Inherits System.ServiceProcess.ServiceBase

#Region " Component Designer generated code "

    Public Sub New()
        MyBase.New()

        ' The Component Designer requires this call.
        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

    ' This is 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 of
        ' code 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(ServicesToRun)
    End Sub

    'The Component Designer requires this code.
    Private components As System.ComponentModel.IContainer

    ' NOTE: The Component Designer requires the following procedure.
    ' You can use the Component Designer to modify the procedure.
    ' However, do not modify use the code editor to modify it.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        Me.ServiceName = "Service1"
    End Sub

#End Region

    Protected Overrides Sub OnStart(ByVal args() As String)
        EventLog.WriteEntry("My simple service started.")
    End Sub

    Protected Overrides Sub OnStop()

    End Sub

End Class

Verify That It Works
On the Start menu, point to Control Panel, point to Administrative Tools, and then click Services.
Right-click Service1, and then click Start.
Use one of the following methods to verify that an event is logged in the event log:
On the Start menu, point to Control Panel, point to Administrative Tools, and then click Event Viewer. Click
Application Log in the left pane, and then locate the event log for your service in the right pane.
In Server Explorer, click to expand the Servers, the ComputerName, the Event Logs, the Application, and
the Service1 nodes. Recall that Service1 is the name of the class, not the service itself. Therefore,
Service1 is used as the application name. (It is beyond the scope of this article to explain how to customize
the names.) Move the cursor over the log entries. The second entry from the top should read "My simple
service started".

0
 
LVL 6

Author Comment

by:carmodyk
ID: 11840860
Thanks a bunch.  Appreciate it.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question