C# 如何解决“'installutil' 未被识别为内部或外部命令、可运行的程序或批处理文件。”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12703645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve "'installutil' is not recognized as an internal or external command, operable program or batch file."?
提问by whytheq
Just tried to run an application via the following:
刚刚尝试通过以下方式运行应用程序:


I have browsed to the directory with an app WindowsService1.exein it, then tried the command Installutil WindowsService1.exebut got the following error...
我已经浏览到包含一个应用程序的目录WindowsService1.exe,然后尝试了该命令,Installutil WindowsService1.exe但出现以下错误...


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.
由于 VS 只安装了一两天,我担心该安装可能有问题,因为它应该识别 installutil。
Are there some basic diagnostics I can perform to ensure that VS Command Prompt is finding all the programs that it should ?
是否有一些基本的诊断我可以执行以确保 VS 命令提示符找到它应该找到的所有程序?
EDIT
编辑
If i run PATHin the command prompt I see the following:
如果我PATH在命令提示符下运行,我会看到以下内容:


采纳答案by Karl-Johan Sj?gren
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.
这有点离题,但我已经停止使用 InstallUtil 来安装我的服务。将它添加到服务本身真的很容易。添加对System.Configuration.Install(如果我没记错的话,在 Client Profile 版本中不可用)的引用,然后像这样更新 Program.cs 中的 Main() 函数。
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.exewith the --installargument and it will install the service and you can forget about InstallUtil.exe.
然后你可以只WindowsService1.exe用--install参数调用,它会安装服务,你可以忘记InstallUtil.exe.
回答by David Mason
Unless you've modified your path, the following should be available in developer command prompt and not cmd:
除非您修改了路径,否则以下内容应该在开发人员命令提示符而不是 cmd 中可用:
- msbuild
- mstest(for ultimate)
- csc
- ilasm
- msbuild
- mstest(终极版)
- 服务中心
- 伊斯兰
... etc
... 等等
If those aren't available you may have a corrupted install.
如果这些不可用,则您的安装可能已损坏。
回答by Daniel
InstallUtil.exe is typically found under one of the versions listed under C:\Windows\Microsoft.NET\Framework.
InstallUtil.exe 通常位于 C:\Windows\Microsoft.NET\Framework 下列出的版本之一下。
In my case it is under v4.0.30319.
就我而言,它在 v4.0.30319 下。
You could just check your path:
你可以检查你的路径:
echo %PATH%
回声%路径%
should give you a list of directories searched for executables.
应该给你一个搜索可执行文件的目录列表。
回答by user3085805
This is what I have done to make it go away:
这是我为让它消失所做的工作:
Found where installutil resides on my PC. In my case it was C:\Windows\Microsoft.NET\Framework\v4.0.30319
Opened a command prompt as an Administrator and changed current directory to above: 'cd C:\Windows\Microsoft.NET\Framework\v4.0.30319'
Then entered: 'installutil C:\MyProgramName.exe'
找到 installutil 在我的 PC 上的位置。就我而言,它是 C:\Windows\Microsoft.NET\Framework\v4.0.30319
以管理员身份打开命令提示符并将当前目录更改为上述目录:'cd C:\Windows\Microsoft.NET\Framework\v4.0.30319'
然后输入:'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.
有趣的是,在上述解决方案之前,我尝试了不同的选项,其中将 C:\Windows\Microsoft.NET\Framework\v4.0.30319 添加到系统路径变量中,但仍然找不到它。
Wish you all smooth installation.
祝大家安装顺利。
回答by Ammu
This might have occurred because you would not have opened the Command Prompt as an administrator or with Administrative Privileges.
这可能是因为您没有以管理员或管理权限打开命令提示符。
回答by user3188978
Found a solution on bytes.com
在 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>
@InstallUtil <Windows 服务的.exe 文件路径>
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 >
@InstallUtil /u <.exe Windows 服务的文件路径>
Save the 2 files as service_install.bat and service_uninstall.bat
将 2 个文件另存为 service_install.bat 和 service_uninstall.bat
Run the files as administrator, every time you have to install or uninstall the service.

每次必须安装或卸载服务时,以管理员身份运行文件。

回答by user7230110
open visual studio command prompt in admin mode i.e., right click on vs command prompt and run as administrator
在管理员模式下打开visual studio命令提示符,即右键单击vs命令提示符并以管理员身份运行
回答by Todd Vance
I got this after I had went back to 2015 from 2017 and I was still using the 2017 command prompt. Something to check.
我从 2017 年回到 2015 年之后得到了这个,我仍在使用 2017 年的命令提示符。要检查的东西。
回答by BattleTested
According Microsoft Page:
根据微软页面:
If you're using the Visual Studio command prompt,
InstallUtil.exeshould 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 :
如果您使用的是 Visual Studio 命令提示符,
InstallUtil.exe则应位于系统路径上。如果没有,您可以将其添加到路径中,或者使用完全限定的路径来调用它。该工具随.NET Framework一起安装,其路径为:
%WINDIR%\Microsoft.NET\Framework[64]\
%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 :
比如32位版本的.NET Framework 4或4.5.*,如果你的Windows安装目录是C:\Windows,那么路径是:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
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 :
对于 .NET Framework 4 或 4.5.* 的 64 位版本,默认路径为:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe
回答by radhason power
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

