I have no experience writing batch scripts, but I was wondering if there was a way to install a .NET Windows service using installutil.exe
using such a script, or u
i'm not sure why you'd need a batch file for a one liner. this is what i'd use.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /i ServiceAssembly.dll
This is the one I use. I found it and use it. Thanx to the creator..
@echo off
SET PROG="YourServiceHere.exe"
SET FIRSTPART=%WINDIR%"\Microsoft.NET\Framework\v"
SET SECONDPART="\InstallUtil.exe"
SET DOTNETVER=2.0.50727
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install
SET DOTNETVER=1.1.4322
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install
SET DOTNETVER=1.0.3705
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install
GOTO fail
:install
ECHO Found .NET Framework version %DOTNETVER%
ECHO Installing service %PROG%
%FIRSTPART%%DOTNETVER%%SECONDPART% %PROG%
GOTO end
:fail
echo FAILURE -- Could not find .NET Framework install
:param_error
echo USAGE: installNETservie.bat [install type (I or U)] [application (.exe)]
:end
ECHO DONE!!!
Pause
This is the batch files I used to install.
@ECHO OFF
REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%
echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i MyService.exe
echo ---------------------------------------------------
echo Done.
pause
To Uninstall I used the following:
@ECHO OFF
REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%
echo Uninstalling MyService...
echo ---------------------------------------------------
InstallUtil /u MyService.exe
echo ---------------------------------------------------
echo Done
I did this with an old fashioned batch file....
Copy the installutil.exe into the same directory as your executable (to make things easier) The following is a generic example of the contents of the batch file necessary: (mine was just names instal.bat)
installutil MyService.exe
sc config MyService type= interact type= own
sc failure MyService reset= 6000 actions= restart/5000/restart/5000/restart/5000
sc start MyService
For more info on command line options for installutil.exe, see here.
To uninstall the service, use a different batch file with the following contents:
installutil MyService.exe /u
create a file with .bat extension and place this in the file
installutil -u c:\YourServiceLocation\Service.exe
You could setup your service exe to support self registration / unregistration using command line arguments (-i -u etc) instead of writing a batch file to do the same thing.
Information on creating Self Installing Services In .NET
http://anotherlab.rajapet.net/2006/06/self-installing-services-in-net.html
http://www.gotnet.biz/WindowsServiceSelfInstaller.ashx
Also adding a Setup Project to your solution and having Visual Studio build an install package might be faster.
How to create a Setup project for a Windows Service in Visual Basic .NET or in Visual Basic 2005
(VB) http://support.microsoft.com/kb/317421
(C#) http://support.microsoft.com/kb/816169