Click here to Skip to main content
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 2: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 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
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