Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deploying a Windows Service

Status
Not open for further replies.

kavsagol

Programmer
Nov 13, 2006
95
0
0
IL
I wrote a Windows service in VB.NET using VS 2003. I added a deployment project for the service. I found out the service should be registered with IntallUtil and then started with NET START, so how do I make the setup program do it automatically? All it does it copy the files.
 
This article shows how to install the service manually, not how to configure the installation project to register it ans start it automatically.
 
Maybe this will help. Sounds like you need to run command lines after the install is complete.

1) create a batch file with your commands, ie. the installUtil and NET Start commands - save as install.bat or any name you want. You might want to add "pause" (without quotes) to the end of your batch file to verify it has run.

2) create a visual basic script file (install.vbs) with the following code:
Set WshShell = CreateObject("WScript.Shell")
strPath = "C:\your path here\install.bat"
WshShell.Run("""" & strpath & """")
Set WshShell = Nothing

3) Right-click the setup project, click View -> Custom Actions
Right-click Commit, select Add
Double-click Application Folder
Click Add File
Browse to install.vbs and add it

4) Right-click the setup project, click Add -> File
Browse and add the batch file (install.bat)

When your setup/deployment exe is done it will call install.vbs which will run install.bat which will run your command lines.

Hope this does it.
 
This almost does it, since the user can change the location of the installed files. Can I get the installtion directory through a parameter in the vbs file? I also need to search for InstallUtil.exe, or maybe it would be wise to add it to the project and delete it after the vbs file has run?
 
To get the install directory try the following (haven't tested this so I can't guarantee it'll work):
Go to the Custom Actions
Set the CustomActionData property of the vbs file to [TARGETDIR]

Change your vbs file to look like:
Set WshShell = CreateObject("WScript.Shell")
curDir = Session.Property("CustomActionData")
WshShell.Run("""" & curDir & "\install.bat" & """")
Set WshShell = Nothing

If the .net framework is required to be on the pc for the windows service to run, you could use it from the following paths:
C:\Windows\Microsoft.Net\framework\v1.1.4322\InstallUtil
C:\Windows\Microsoft.Net\framework\v2.0.50727\InstallUtil

Or your suggestion would work also by including it and then deleting it.
 
Here's the link I used -

:) -Andrew

alien.gif

[Signature modified by admin request]
-TAG
[Contact information removed by another admin request]
 
10x AnonGod, that's exactly what I need. Is there a way to start the service from the installer or should I add a vbs/exe file for this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top