Click here to Skip to main content
11,709,844 members (49,925 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows service
I want to Install or Uninstall Windows Service Using batch File.
Please Help
Posted 7-Dec-12 1:37am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Install

@echo off
SET PROG=%"%C:\Program Files\CallCenterCRMWindowsService%"%
SET SERVICE_EXE=%"%\CallCenterCRMWindowsService.exe%"%
SET FIRSTPART=%WINDIR%"\Microsoft.NET\Framework\v"
SET SECONDPART="\InstallUtil.exe"
SET SERVICENAME=%"%SynchronizeData%"%
SET DELETEBATCH="\*.bat"

SET DOTNETVER=4.0.30319
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install
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%"
MD "%PROG%"
COPY *.* "%PROG%"
del "%PROG%"%DELETEBATCH%
%FIRSTPART%%DOTNETVER%%SECONDPART% /name=%SERVICENAME% "%PROG%%SERVICE_EXE%"
GOTO end
:fail
echo FAILURE -- Could not find .NET Framework install
:end
ECHO DONE!!!
Pause

UnInstall

@echo off
SET PROG=%"%C:\Program Files\CallCenterCRMWindowsService%"%
SET SERVICE_EXE=%"%\CallCenterCRMWindowsService.exe%"%
SET FIRSTPART=%WINDIR%"\Microsoft.NET\Framework\v"
SET SECONDPART="\InstallUtil.exe"
SET SERVICENAME=%"%SynchronizeData%"%
SET DELETEBATCH="\*.bat"
SET DOTNETVER=4.0.30319
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install
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 Uninstalling service "%PROG%"
%FIRSTPART%%DOTNETVER%%SECONDPART% /U /name=%SERVICENAME% "%PROG%%SERVICE_EXE%"
RD "%PROG%" /s
GOTO end
:fail
echo FAILURE -- Could not find .NET Framework install
:end
ECHO DONE!!!
Pause
  Permalink  
Comments
Member 7909353 at 25-Nov-13 8:40am
   
@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 c:\abc.exe
net start | find "AutomateSMS" > nul 2>&1
if not .%errorlevel%.==.0. goto startservice
goto skip

:startservice
net start "abc"

echo ---------------------------------------------------
echo Done.
stop


why it ask for username ,password

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 524
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100