How to resolve "'installutil' is not recognized as an internal or external command, operable program or batch file."?

C#Visual StudioVisual Studio-2012Cmd

C# Problem Overview


Just tried to run an application via the following:

enter image description here

I have browsed to the directory with an app WindowsService1.exe in it, then tried the command Installutil WindowsService1.exe but got the following error...

enter image description here

As VS has only been installed for a day or two I'm worried that something may be wrong with that install as it should recognise installutil.

Are there some basic diagnostics I can perform to ensure that VS Command Prompt is finding all the programs that it should ?

EDIT

If i run PATH in the command prompt I see the following:

enter image description here

C# Solutions


Solution 1 - C#

This is a tiny bit off-topic but I've stopped using InstallUtil to install my services. It's is really easy to just add it to the service itself. Add a reference to System.Configuration.Install (not available in the Client Profile editions if I remember right) and then update your Main()-function in Program.cs like this.

static void Main(string[] args) {
    if (Environment.UserInteractive) {
        var parameter = string.Concat(args);
        switch (parameter) {
            case "--install":
                ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
                break;
            case "--uninstall":
                ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
                break;
        }
    } else {
        ServiceBase[] servicesToRun = { 
            new Service1() 
        };
        ServiceBase.Run(servicesToRun);
    }
}

Then you can just call WindowsService1.exe with the --install argument and it will install the service and you can forget about InstallUtil.exe.

Solution 2 - C#

This is what I have done to make it go away:

  1. Found where installutil resides on my PC. In my case it was C:\Windows\Microsoft.NET\Framework\v4.0.30319

  2. Opened a command prompt as an Administrator and changed current directory to above: 'cd C:\Windows\Microsoft.NET\Framework\v4.0.30319'

  3. Then entered: 'installutil C:\MyProgramName.exe'

Interestingly, prior to above solution I tried different options, among them adding C:\Windows\Microsoft.NET\Framework\v4.0.30319 to the System Path variable, but it still could not find it.

Wish you all smooth installation.

Solution 3 - C#

InstallUtil.exe is typically found under one of the versions listed under C:\Windows\Microsoft.NET\Framework.

In my case it is under v4.0.30319.

You could just check your path:

echo %PATH%

should give you a list of directories searched for executables.

Solution 4 - C#

Found a solution on bytes.com

The code to install a service:

@ECHO Installing Service...
@SET PATH=%PATH%;C:\Windows\Microsoft.NET\Framework\v4.0.30319\
@InstallUtil  C:\Unlock_4_Service\bin\Debug\Unlock_4_Service.exe
@ECHO Install Done.
@pause

@InstallUtil <.exe file path of your windows service>

Code to uninstall the service

@ECHO Installing Service...
@SET PATH=%PATH%;C:\Windows\Microsoft.NET\Framework\v4.0.30319\
@InstallUtil /u C:\Unlock_4_Service\bin\Debug\Unlock_4_Service.exe
@ECHO Uninstall Done.
@pause

@InstallUtil /u <.exe file path of your windows service >

Save the 2 files as service_install.bat and service_uninstall.bat

Run the files as administrator, every time you have to install or uninstall the service. enter image description here

Solution 5 - C#

Before Installing service using command line...

use 2 steps:

  1. cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
  2. InstallUtil.exe Path\MyWindowsService.exe

Solution 6 - C#

Just add the installUtil.exe path in the environment variable to fix this issue.

Example:

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

Solution 7 - C#

Unless you've modified your path, the following should be available in developer command prompt and not cmd:

  • msbuild
  • mstest(for ultimate)
  • csc
  • ilasm

... etc

If those aren't available you may have a corrupted install.

Solution 8 - C#

This might have occurred because you would not have opened the Command Prompt as an administrator or with Administrative Privileges.

Solution 9 - C#

open visual studio command prompt in admin mode i.e., right click on vs command prompt and run as administrator

Solution 10 - C#

According Microsoft Page :

>If you’re using the Visual Studio command prompt, InstallUtil.exe should be on the system path. If not, you can add it to the path, or use the fully qualified path to invoke it. This tool is installed with the .NET Framework, and its path is :

%WINDIR%\Microsoft.NET\Framework[64]<framework_version>

>For example, for the 32-bit version of the .NET Framework 4 or 4.5.*, if your Windows installation directory is C:\Windows, the path is :

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

>For the 64-bit version of the .NET Framework 4 or 4.5.*, the default path is :

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

Solution 11 - C#

I got this after I had went back to 2015 from 2017 and I was still using the 2017 command prompt. Something to check.

Solution 12 - C#

Add this in windows Environmental variables
First: Right click on My computer or This PC
Second: Click on Environmental Variables
Third: add this path after clicking on path
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe

Solution 13 - C#

This is somewhat off-topic as it's for use in a C# program, not for command-line use. What we did was locate the InteropServices runtime directory at runtime, eliminating the need to add or use a Path variable. This directly gets the Microsoft.NET Framework utilities folder. Here's a method.

using System.Diagnostics;

	public static void InstallService(string serviceExe, bool uninstall = false)
	{
		string installUtilPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + "InstallUtil.exe";
		Process installProc = new Process();
		installProc.StartInfo.FileName = installUtilPath;
		installProc.StartInfo.Arguments = (uninstall ? " /u " : string.Empty) + @"""" + serviceExe + @"""";
		installProc.StartInfo.UseShellExecute = false;
		installProc.StartInfo.RedirectStandardOutput = true;
		installProc.StartInfo.RedirectStandardError = true;
		installProc.StartInfo.CreateNoWindow = true;
		installProc.Start();
		installProc.WaitForExit();
		Debug.WriteLine(installProc.StandardOutput.ReadToEnd());
		if (installProc.ExitCode != 0)
		{
			throw new Exception($"Failed to install service: {serviceExe}. Exit code: {installProc.ExitCode}\n Review {serviceExe}.InstallLog for details.\n" +
				$" Utility path: {installUtilPath}.");
		}
	}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwhytheqView Question on Stackoverflow
Solution 1 - C#Karl-Johan SjögrenView Answer on Stackoverflow
Solution 2 - C#user3085805View Answer on Stackoverflow
Solution 3 - C#DanielView Answer on Stackoverflow
Solution 4 - C#user3188978View Answer on Stackoverflow
Solution 5 - C#Abdulla Al MamunView Answer on Stackoverflow
Solution 6 - C#YogiView Answer on Stackoverflow
Solution 7 - C#David MasonView Answer on Stackoverflow
Solution 8 - C#AmmuView Answer on Stackoverflow
Solution 9 - C#user7230110View Answer on Stackoverflow
Solution 10 - C#BattleTested_закалённый в боюView Answer on Stackoverflow
Solution 11 - C#Todd VanceView Answer on Stackoverflow
Solution 12 - C#ranojanView Answer on Stackoverflow
Solution 13 - C#pwrgreg007View Answer on Stackoverflow