How to resolve “'installutil' is not recog

2019-01-20 23:28发布

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

9条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-20 23:47

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

查看更多
3楼-- · 2019-01-20 23:52

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)
    {
        string 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 ServiceBase[] 
                          { 
                              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.

查看更多
Viruses.
4楼-- · 2019-01-20 23:52

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

查看更多
祖国的老花朵
5楼-- · 2019-01-21 00:03

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.

查看更多
We Are One
6楼-- · 2019-01-21 00:03

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]\

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

查看更多
叛逆
7楼-- · 2019-01-21 00:06

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

查看更多
登录 后发表回答