By Vikash Pandey


2011-11-17 09:32:07 8 Comments

I want to install a Windows service using a Windows command prompt (not the Visual Studio command prompt).

How do I do this?

16 comments

@Sid 2017-10-30 01:26:02

Nothing wrong with SC Create command. Just you need to know the correct args :

SC CREATE "MySVC" binpath= "D:\Me\Services\MySVC\MySVC.exe"

@Alejandro 2017-11-01 13:21:00

This is the only answer that references the official way to install/modify/delete a service. Moreover, this doesn't depends on the .NET Framework being installed and works with any kind of file, not just .NET binaries.

@Sid 2017-12-22 08:32:50

Yep..thats why i loved this approach and always advice it since all the work needs to be done into the exe which can belong to any .net fw version.

@Paramvir Singh Karwal 2019-09-27 08:18:49

why does it give me ` A positional parameter cannot be found that accepts argument 'binpath='. `

@Captain Dashenka 2019-10-07 13:02:26

worth noting that this command is only available for windows server ( and some older windows versions ). Win 10 has an sc command also but it's something different, can't be used to register services.

@Urk 2019-10-07 15:30:38

Note that the space after "binpath= " is imperative. @ParamvirSinghKarwal

@russelrillema 2019-10-15 08:02:40

This should be the accepted answer.

@Danish Sulaiman 2019-09-29 07:33:01

Open command prompt as administrator, go to your Folder where your .exe resides. To Install Exe as service

D:\YourFolderName\YourExeName /i

To uninstall use /u.

@Hamit YILDIRIM 2019-07-05 22:42:08

Fallow the steps when deploying the Windows Service, don't lost time

1- Run command prompt by the Admin right

2- Insure about release mode when compilling in your IDE

3- Give a type to your project installer on design view

4- Select authentication type in accordance the case

5- Insure about software dependencies: If you are using a certificate install it correctly

6- Go your console write this:

C:\Windows\Microsoft.NET\Framework\yourRecentVersion\installutil.exe c:\yourservice.exe

there is a hidden -i argument before the exe path -i c:\ you can use -u for uninstallling

7- Look your .exe path to seem log file. You can use event viewer to observing in the feature

@Pawel Wujczyk 2018-02-15 19:26:14

If you are using Powershell and you want to install .NET service you can use Install-Service module. It is a wrapper for InstalUtil tool.

It exposes 3 commands

  • Install-Service - invokesĀ InstallUtil.exe pathToExecutable command
  • Install-ServiceIfNotInstalled - first it checks if service is installed if not perform the method Install-Service
  • Uninstall-Service- it uninstalls service. ServiceName of path to executable can be used.

Code to this module can be viewed here

@Kaushik AppzyTech 2017-11-01 12:52:18

Install Service:-

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" 
"C:\Services\myservice.exe"

UnInstall Sevice:-

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" -u "C:\Services\myservice.Service.exe"

@saber tabatabaee yazdi 2017-04-05 12:31:56

when your assembly version and your Visual studio project Biuld setting on dot net 2 or 4 install with same version.

install service with installutil that same version

if build in dot net 4

Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe

if build in dot net 2

Type c:\windows\microsoft.net\framework\v2.0.11319\installutil.exe

@Joji Thomas Eapen 2018-09-16 07:23:57

the following code , install and uninstall the Service,

Open the command prompt and run the program as an administrator and fire the below command and press enter.

Syntax

To Install

C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe + Your copied path + \your service name + .exe

eg :Our Path InstallUtil.exe C:\MyFirstService\bin\Debug\MyFirstService.exe

To uninstall

 C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe -u + Your copied path + \your service name + .exe

eg : Our path InstallUtil.exe -u C:\MyFirstService\bin\Debug\MyFirstService.exe

for more help you can see the following link: sample program

@Base33 2012-07-26 00:29:04

Perform the following:

  1. Start up the command prompt (CMD) with administrator rights.
  2. Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
  3. Press return and that's that!

It's important to open with administrator rights otherwise you may find errors that come up that don't make sense. If you get any, check you've opened it with admin rights first!

To open with admin rights, right click 'Command Prompt' and select 'Run as administrator'.

Source: http://coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/

@Karan Raiyani 2018-08-10 14:03:40

Open Visual studio and select new project by selecting Windows Service template in Windows Desktop tab. Than copy following code into your service_name.cs file.

using System.Diagnostics;
using System.ServiceProcess;
namespace TimerService
{
    public partial class Timer_Service : ServiceBase
    {
        public Timer_Service()
        {
            InitializeComponent();
        }
        static void Main()
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Timer_Service service = new Timer_Service();
                service.OnStart(null);
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new Timer_Service()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service start successfully." });
        }
        protected override void OnStop()
        {            
            EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service stop successfully." });
        }
    }
}

Right-Click on service_name.cs file and open designer of service. than right-click and select Add Installer. than right-click on serviceProcessInstaller1 and change its property value of Account from User to Local System.

Remove static void main method from Program.cs file. Than save and Build your project.

NOTE: goto bin\Ddebug folder of your project folder. Than open Properties of your service_name.exe file. Than goto Compatibility tab. Than click on Change Settings For All Users.

Select option Run this program as an administrator.

Now, You have to open CommandPromt as Administrator. After open, set directory to where your InstallUtil.exe file is placed. for ex: C:\Windows\Microsoft.NET\Framework64\v4.0.30319. now write the following command:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe -i C:\TimerService\TimerService\bin\Debug\TimerService.exe

Note: -i is for install he service and -u for Unsinstall.

after -i set the write the path where you want to install your service.

now write the command in CommandPromt as follows:

C:\TimerService\TimerService\bin\Debug>net start service_name

Note: use stop for stop the Service.

Now, open ViewEventLog.exe. Select Windows Logs>Application. There you can check your Service's log by start and stop the service.

@Mohammad Dayyan 2018-07-07 11:54:47

Create a *.bat file beside of your windows service exe file for installing with the following context:

CLS
ECHO Installing My Windows Service 

START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe "%~d0%~p0\YourWindowsServiceExeName.exe"

Create a *.bat file beside of your windows service exe file for uninstalling with the following context:

CLS
ECHO Uninstalling My Windows Service 

START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "%~d0%~p0\YourWindowsServiceExeName.exe"

Run each of bat file as Admin to install or uninstall your windows service.

@Soft-Web Expert 2018-05-02 18:19:24

You should open command prompt, go to

C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i ".EXE file of window service"

@MKR 2017-12-15 12:29:20

I must add one more point in this thread. To install/uninstall 64-bit version of assemblies one should use 64-bit version of tool. To install a service, the command should be:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe"
"C:\YourFolder\YourService.exe"

and to uninstall the command should be:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" -u
"C:\YourFolder\YourService.exe"

@Oguzhan KIRCALI 2017-10-17 06:56:49

  1. Run Windows Command Prompt as Administrator
  2. paste this code: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\ to go to folder
  3. edit and run this too: installutil C:\ProjectFolder\bin\Debug\MyProject.exe

Note: To uninstall: installutil /u C:\ProjectFolder\bin\Debug\MyProject.exe

@what server 2017-04-14 10:08:37

  1. start up the command prompt (CMD) with administrator rights.
  2. Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
  3. Press return

@Dhanuka777 2014-03-13 08:34:57

If the directory's name has a space like c:\program files\abc 123, then you must use double quotes around the path.

installutil.exe "c:\program files\abc 123\myservice.exe"

Install windows service from command prompt

It makes things much easier if you set up a bat file like following,

e.g. To install a service, create a "myserviceinstaller.bat" and "Run as Administrator"

@echo off
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
installutil.exe "C:\Services\myservice.exe"

if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem
pause

to uninstall service,

Just add a -u to the installutil command.

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "C:\Services\myservice.exe"

@hcb 2011-11-17 09:52:12

Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe"

@fabriciorissetto 2015-08-29 21:36:18

Don't forget to run the command prompt "as Administrator"

@nme 2016-02-23 10:10:20

If it is the x64 compiled service, use "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil‌​.exe".

@Nick 2016-03-22 14:39:07

I get a weird error. No public installer with the RunInstallerAttribute. Yes attribute could be found in the .exe assembly. Remove InstallState file because there are no installers

@ShaileshDev 2017-01-05 13:59:00

Hi, I tried this solution but its giving exception as "...file not found or one of its dependencies." Please help.

@Cataklysim 2017-07-11 12:01:30

For everyone with the same problem as all these and me: You dont need to put the whole path in it anymore. a simple installutil.exe "C:\YourProject.exe" is enough.

@Robin French 2017-09-21 16:09:12

Is there any difference between installutil in 'Framework' and 'Framework64'?

@BluE 2018-08-08 14:14:30

@Cataklysim You do have to use the full path, unless you added it to the path environment variable.

Related Questions

Sponsored Content

42 Answered Questions

[SOLVED] How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?

  • 2008-09-29 22:30:28
  • mistrmark
  • 1037976 View
  • 1790 Score
  • 42 Answer
  • Tags:   c# .net excel file-io

15 Answered Questions

[SOLVED] Aliases in Windows command prompt

37 Answered Questions

[SOLVED] Error - Unable to access the IIS metabase

  • 2012-10-12 13:15:03
  • jjathman
  • 348553 View
  • 828 Score
  • 37 Answer
  • Tags:   c# .net iis

6 Answered Questions

22 Answered Questions

7 Answered Questions

[SOLVED] Install Windows Service created in Visual Studio

12 Answered Questions

[SOLVED] Run Command Prompt Commands

12 Answered Questions

[SOLVED] How can I delete a service in Windows?

17 Answered Questions

[SOLVED] How to solve "The specified service has been marked for deletion" error

  • 2013-12-13 08:20:42
  • Arseni Mourzenko
  • 432171 View
  • 531 Score
  • 17 Answer
  • Tags:   windows-services

13 Answered Questions

[SOLVED] How do I uninstall a Windows service if the files do not exist anymore?

Sponsored Content