473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

VB.Net 2.0 (VS 2005) - Deploy a Windows Service such that it is INSTALLED?

MTEXX
5
I have used the Windows Service template to create, well, a Windows Service. It starts, stops, pauses etc. Works great.

I added an Setup project. It builds an .msi (and .exe) file. I thought I was almost finished. I uninstalled my service (InstallUtil.exe via a External Tools macro I made- ask about that).

I ran the newly created installation program. It indeed installed my service exe using the familiar installer wizard. However when I looked in my Services list, it wasn't there! Even after a reboot. Sooooo. To truly deploy a Windows Service, InstallUtil must be run. And likewise, to uninstall !!! This is unacceptable. When I install professional software, it doesn't ask me to run some command line program (think like a normal user), which doesn't come installed with Windows anyway : {

-MTEXX
Feb 4 '08 #1
3 6584
radcaesar
759 Expert 512MB
In Background it does.

Here is your solution,

http://claytonj.wordpress.com/2006/06/05/installing-a-windows-service-using-a-setup-project/
Feb 5 '08 #2
MTEXX
5
Thanks for the link radcaesar.

During the course of yesterday's work, I came across that as well.
To others reading- make SURE you add Custom Actions for both Install and Uninstall. In both actions, do "Add Custom Action" pointing to "Application Folder \ Primary output from __YourServiceProjectName__".

Now for another issue.

When installing the service, it is not Started. Likewise, the uninstall doesn't Stop the service first...

Here are two overrides for the __YourServiceProject__\ProjectInstaller1 code:
'ServiceInstaller is by default named ServiceInstaller1 :

Expand|Select|Wrap|Line Numbers
  1.     Private Sub ServiceInstaller_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterInstall
  2.         Dim displayName As String = ServiceInstaller.DisplayName
  3.  
  4.         MsgBox("ServiceInstaller_AfterInstall: " & System.Reflection.Assembly.GetExecutingAssembly.Location(), MsgBoxStyle.OkOnly)
  5.         'find the service by display name
  6.         Dim scs() As ServiceController = ServiceController.GetServices()
  7.         Dim sc As ServiceController = Nothing
  8.         For Each i As ServiceController In scs
  9.             If (i.DisplayName = displayName) Then
  10.                 sc = i
  11.                 'Console.WriteLine(sc.ServiceName)
  12.                 Exit For
  13.             End If
  14.         Next
  15.         If (sc Is Nothing) Then
  16.             'Console.WriteLine("ERROR InstallerStuff::installDotNetService() could not find installed service by display name.")
  17.             MsgBox("Service failed to install")
  18.             Return
  19.         End If
  20.  
  21.         'start service (if not running...)
  22.         If (sc.Status = ServiceControllerStatus.Stopped) Then
  23.             sc.Start()
  24.             sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10))
  25.             If (sc.Status <> ServiceControllerStatus.Running) Then
  26.                 MsgBox("Service failed to start." & vbCrLf & "Please start " & displayName & " via ControlPanels\Services," & vbCrLf & "...or restart computer")
  27.                 Return
  28.             End If
  29.         End If
  30.         MsgBox("Service started")
  31.     End Sub
  32.  
  33.     Private Sub ServiceInstaller_AfterRollback(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterRollback
  34.         MsgBox("ServiceInstaller_AfterRollback", MsgBoxStyle.OkOnly)
  35.     End Sub
  36.  
  37.     Private Sub ServiceInstaller_AfterUninstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterUninstall
  38.         MsgBox("ServiceInstaller_AfterUninstall", MsgBoxStyle.OkOnly)
  39.     End Sub
  40.  
  41.     Private Sub ServiceInstaller_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeInstall
  42.         MsgBox("ServiceInstaller_BeforeInstall", MsgBoxStyle.OkOnly)
  43.     End Sub
  44.  
  45.     Private Sub ServiceInstaller_BeforeRollback(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeRollback
  46.         MsgBox("ServiceInstaller_BeforeRollback", MsgBoxStyle.OkOnly)
  47.     End Sub
  48.  
  49.     Private Sub ServiceInstaller_BeforeUninstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeUninstall
  50.         MsgBox("ServiceInstaller_BeforeUninstall " & ServiceInstaller.DisplayName, MsgBoxStyle.OkOnly)
  51.         Dim displayName As String = ServiceInstaller.DisplayName
  52.         'MsgBox("ServiceInstaller_AfterInstall: " & System.Reflection.Assembly.GetExecutingAssembly.Location(), MsgBoxStyle.OkOnly)
  53.  
  54.         'find the service by display name
  55.         Dim scs() As ServiceController = ServiceController.GetServices()
  56.         Dim sc As ServiceController = Nothing
  57.         For Each i As ServiceController In scs
  58.             If (i.DisplayName = displayName) Then
  59.                 sc = i
  60.                 Exit For
  61.             End If
  62.         Next
  63.         If (sc Is Nothing) Then
  64.             MsgBox("Could not find service '" & displayName & "' to stop.")
  65.             Return
  66.         End If
  67.  
  68.         'start service (if not running...)
  69.         If (sc.Status <> ServiceControllerStatus.Stopped) Then
  70.             sc.Stop()
  71.             sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10))
  72.             If (sc.Status <> ServiceControllerStatus.Stopped) Then
  73.                 MsgBox("Service failed to stop, but should be queued for deletion after next reboot.")
  74.                 Return
  75.             End If
  76.         End If
  77.         MsgBox("Service stopped")
  78.     End Sub
Feb 6 '08 #3
I just created my first Windows Service in VS2005. Your article was exactly what I needed to finish up!

Rob W
Jun 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lynne | last post by:
I've created a windows service and installed it using the installutil. If I have an update version of the service's exe (or associated dll), is it necessary to uninstall the service and reinstall...
0
by: James N | last post by:
I want to write a Windows Service application that will detect and then perform some tasks whenever a client logs on to the domain. This service will be running on a server with Active Directory. ...
1
by: RaggiHolm | last post by:
I am writing a service that I want to be able to display "debug" information on a desktop window. I have the following code that displays the form (when service is properly set up) and the service...
7
by: Larry Bird | last post by:
I have a windows service that want to un-install. When I run "installutil /u serivcename" I get the error that the serivce is not installed on my machine. However, when view the serivce console I...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
2
by: gabe | last post by:
Does anyone have a resource for deploying a windows service? - creatng a setup project to deply a windows service project, getting InstallUtil.exe to execute (and reference the correct framework...
0
by: Univar | last post by:
I apologize now if the answer is somewhere else on this site but I was unable to find an adequate explanation. I have recently decided to create a Windows Service to act as a client for a processor...
3
by: mtczx232 | last post by:
I wonder what the best way to run Service, and be able to Interact with him, and show the DataTable from Service. the first way is: build Service project, and Interact with him by remoting, and use...
2
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
I am familiar with how to use winsock in vb6 to create a network app. I'm trying to find a way to take the current vb6 app and create a windows service using system.net.sockets. How do you create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.