Using Developer Command Prompt
You can install a service using following command in Visual Studio Developer Command Prompt
installutil.exe YourService.exe
You can find Visual Studio Developer Command Prompt in
Start -- Visual Studo XXXX -- Visual Studio Tools -- Developer Command Prompt for VSXXXX
Make sure that you have opened this with "Run as administrator" (Right click -- Run as administrator)
Using Windows Command Prompt
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" YourService.exe
Note: v4.0.30319 can be different on your machine
Using Setup Project
But if you want to install the service through setup project then follow these steps-
1. Open your service file (ex. Service1.cs) in
Design Mode, right click and click
Add Installer. Note that 2 controls will be visible now with name like
serviceProcessInstaller1 and
ServiceInstaller1
2. n the Properties pane, change the
Account property to
LocalSystem
3. Right click on
ServiceInstaller1 and change
StartType property to
Automatic
4. Do the changes as per you requirement, if any (like service name etc.)
5. Add a
Setup Project to your solution
6. In Solution Explorer, right-click on your setup project, select
Add and then click
Project Output
7. In the
Add Project Output Group dialog box, in the Project box, click YourServiceName. Click
Primary Output, and then click
OK.
8. Build the whole solution.
Your setup should be ready.
UPDATE:
Using Batch File
1. Open Notepad
2. Paste following code and change the service name (& framework version if required)
@ECHO OFF
REM The following directory is for .NET 4.0 & you may change according to framework version installed in your system
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil" "YourService.exe"
3. From
File click
SaveAs. Save it with a name and with extension
.bat
4. Execute this batch file from the same location where your service exe is placed.
Hope, it helps :)