is there any installer to install the windows service

naresh

Active member
Joined
Jul 4, 2006
Messages
38
Programming Experience
1-3
Hi,
this Question is already raised. Still i am asking this one is there any installer to install the windows service. I use Setup factory to install the applications. can i use the setup factory to instll. if yes please suggest the way to install. the service was made in .net 2005 i,e., frame work 2.0.

thanks in advance.
 
I will read the links on editing the Registry but adding the shortcut to the start menu hasn't worked. I looked it up and I'm not the only person that it doesn't work for. Some said XP doesn't do it that way anymore but I don't know. If you know about this error then maybe a tip on the situation will help. However; after what I have read the registry looks to be the best answer. Again, when I add the key Run or Run Once, which i know nothing about yet, I have also read that when un-installing the app you can't remove this key or it will remove all run keys.
 
Just a clarification, the mentioned 'Run' and 'RunOnce' are registry keys, you have to add you app into these as name/value pairs, for example to that key you can add name "myapp" with value "c:\path\myapp.exe", and remove that name/value when uninstalling (not the whole registry.. *laughs*). An entry in registry key 'RunOnce' will execute next time system starts and be removed automatically, and entry in 'Run' will execute every time system starts.

You can run RegEdit.exe and navigate it for a better view of what is being talked about; in the left pane is a treeview displaying the hives with the key structure and the right pane displays the name/value pairs. You could also try to add your entry there manually first through RegEdit application and check out how it works, when confident about its modus operandi automate it with programming language.

Creating a shortcut with WSH library has never been a problem and never will, WSH is the operating systems integrated scripting language for windows administration (It is also the host for running VBScript and JavaScript from your desktop.). Example:
VB.NET:
'first Add Reference to Windows Script Host (COM tab in dialog)
 
Sub createStartupShortcut()
    Dim shell As New IWshRuntimeLibrary.WshShell
    Dim deskPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
    Dim x As IWshRuntimeLibrary.WshShortcut
    x = DirectCast(shell.CreateShortcut(deskPath & "\calc shortcut.lnk"), IWshRuntimeLibrary.WshShortcut)
    x.Description = "Calculator"
    x.TargetPath = "calc.exe"
    x.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)
    x.Save()
End Sub
 
Ok, so... I am installing my program into the normal Program Files Folder in windows. Now with VS2005 when I add a Project Installer I can right click in the solution explorer and choose view Registry. At that point I can add keys, ect... I don't want to guess and choose until I get it right b/c I know the registry isn't a place to play. Can you give me a quick walk though of adding the key at that point? I want it to be in the 'Run' not 'RunOnce'. Also I am reading the links you sent me about the Registry right now. Thanks :)
 
Sure, add to HKEY_CURRENT_USER all these keys until you got the full path "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", with the last 'Run' key selected add Name/Value pair of type String, the Name could be "my application" and value could be "[TARGETDIR]myApp.exe". [TARGETDIR] is automatically translated to the install path.
 
Thanks a ton. I finally figured it out after reading all your posts and links but I took the option to choose installation path out b/c I didn't know how to change that. So [TARGETDIR] helps me even more. You've been a great help. Thanks a ton :)
 
Empty Service Template

Here is an empty service template. I reuse it a lot. Hope it helps. The settings at the very bottom are the most important about installer

Update the code (onstart, onstop, ontimer), change the name from EMPTYSERVICE and include in a service project, and copy the bin to install machine.
Then run, from .net command prompt, installutil -i nameofexe.exe
To uninstall just run installutil.exe -u nameofexe.exe

VB.NET:
Option Explicit On 
Imports System
Imports System.Net
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Text
Imports System.Timers
Imports System.Configuration.ConfigurationSettings
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.ServiceProcess
Imports System.Configuration.Install
Imports System.Windows.Forms.Application
Public Class EMPTY_SERVICE
Inherits System.ServiceProcess.ServiceBase
Friend WithEvents oTimer As System.Timers.Timer
#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 EMPTY_SERVICE}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'EMPTY_SERVICE
'
Me.ServiceName = "EMPTY_SERVICE"
End Sub
#End Region
Protected Overrides Sub OnStart(ByVal args() As String)
Try
oTimer = New System.Timers.Timer
AddHandler oTimer.Elapsed, AddressOf oTimer_HasElapsed
oTimer.Interval = 5000
oTimer.Enabled = True
Catch ex As Exception
Stop
End Try
End Sub
Protected Overrides Sub OnStop()
Try
oTimer.Enabled = False
oTimer = Nothing
Catch ex As Exception
Stop
End Try
End Sub
Public Sub oTimer_HasElapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
Try
System.Diagnostics.EventLog.WriteEntry("Application", "The test message " & Date.Now, Diagnostics.EventLogEntryType.Information)
Catch ex As Exception
Stop
End Try
End Sub
End Class
 
<RunInstallerAttribute(True)> _
Public Class ProjectInstaller
Inherits Installer
Private serviceInstaller As ServiceInstaller
Private processInstaller As ServiceProcessInstaller
Private otherServiceInstaller As ServiceInstaller
Sub New()
processInstaller = New ServiceProcessInstaller
serviceInstaller = New ServiceInstaller
processInstaller.Account = ServiceAccount.LocalSystem
serviceInstaller.StartType = ServiceStartMode.Automatic
serviceInstaller.ServiceName = "EMPTY_SERVICE"
Installers.Add(serviceInstaller)
Installers.Add(processInstaller)
End Sub
End Class
 
Last edited by a moderator:
Back
Top