DaveRowland
asked on
Installing and Packaging a Windows Service (VB.NET)
Hi, I seen the articles of making a Windows Service and using InstallUtil and InstallUtil /u
But, how do I now take this one step further and put it into a deployment setup.exe, what I require is guidence to make a setup program to put on a distrubtion CD. I know how to do it for a basic install windows form, but for a Windows Service and shelling out to InstallUtil might be okay, but how do you do that ? or even what is the best way of getting this installed correctly and running quickly?
A typical Windows Service program that I have open. ( it is an exciting one!! )
Imports System.ServiceProcess
Public Class Service1
Inherits System.ServiceProcess.Serv iceBase
#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.Serv iceBase
' 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.Serv iceBase () {New Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.Serv iceBase () {New Service1}
System.ServiceProcess.Serv iceBase.Ru n(Services ToRun)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.ICon tainer
' 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.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
components = New System.ComponentModel.Cont ainer()
Me.ServiceName = "Service1"
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.
MsgBox("Starting the service")
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
MsgBox("Stopping the service")
End Sub
End Class
But, how do I now take this one step further and put it into a deployment setup.exe, what I require is guidence to make a setup program to put on a distrubtion CD. I know how to do it for a basic install windows form, but for a Windows Service and shelling out to InstallUtil might be okay, but how do you do that ? or even what is the best way of getting this installed correctly and running quickly?
A typical Windows Service program that I have open. ( it is an exciting one!! )
Imports System.ServiceProcess
Public Class Service1
Inherits System.ServiceProcess.Serv
#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.Serv
' 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.Serv
'
ServicesToRun = New System.ServiceProcess.Serv
System.ServiceProcess.Serv
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.ICon
' 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.
<System.Diagnostics.Debugg
components = New System.ComponentModel.Cont
Me.ServiceName = "Service1"
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.
MsgBox("Starting the service")
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
MsgBox("Stopping the service")
End Sub
End Class
I avoid that problem by having the service install itself by looking for a -i on the command line.
or write a small application that excutes the service for u
main(){
Process.Start("InstallUtil .exe");
}
and this small application to the install folder of the project installer. So it runs during installation, and installs your services.
main(){
Process.Start("InstallUtil
}
and this small application to the install folder of the project installer. So it runs during installation, and installs your services.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for both methods. I suspect I will split the points, both have given me tips on what I am looking for:
I am not a C programmer, so I will read carefully through that solution. I can see where you are going with that.
Also this process.start InstallUtil.exe line, this is fair enough but my developer station doesn't seem to be 'path'ed to the Commands folder in framework which would mean I have to package it and this just doesn't feel right (licencing and just the normallity of it all)
I will try and compile the C version and se how it works.
I am not a C programmer, so I will read carefully through that solution. I can see where you are going with that.
Also this process.start InstallUtil.exe line, this is fair enough but my developer station doesn't seem to be 'path'ed to the Commands folder in framework which would mean I have to package it and this just doesn't feel right (licencing and just the normallity of it all)
I will try and compile the C version and se how it works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddinginstallerstoyourserviceapplication.asp
Create your setup project and custom action to deploy and install your service. For more information on setup projects, see Setup Projects. For more information on custom actions, see Walkthrough: Creating a Custom Action.
Well I manged to make a simple Install in the custom actions, only took me a few minutes.
I shall split some points as I was guided through this by Zinno and Cookre
Create your setup project and custom action to deploy and install your service. For more information on setup projects, see Setup Projects. For more information on custom actions, see Walkthrough: Creating a Custom Action.
Well I manged to make a simple Install in the custom actions, only took me a few minutes.
I shall split some points as I was guided through this by Zinno and Cookre