如何解决“'installutil'不被识别为内部或外部命令,可操作的程序或批处理文件。 [英] How to resolve "'installutil' is not recognized as an internal or external command, operable program or batch file."?

查看:806
本文介绍了如何解决“'installutil'不被识别为内部或外部命令,可操作的程序或批处理文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是尝试通过以下方式运行应用程序:





我已经浏览到目录中的应用程序 WindowsService1.exe ,然后尝试命令 Installutil WindowsService1.exe ,但得到以下错误...





由于VS只安装了一天,两个我担心安装时可能会出错,因为它应该能识别installutil。



是否有一些基本诊断可以执行,以确保VS命令提示符找到



如果我运行 PATH 在命令提示符下,我看到以下内容:



解决方案

我已停止使用InstallUtil来安装我的服务。它是很容易只是添加到服务本身。添加对 System.Configuration.Install 的引用(如果我记得正确的话,在客户端配置文件版本中不可用),然后在Program.cs中更新您的Main() - 函数,像这样。

  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);
}
}

然后你可以调用 WindowsService1.exe - install 参数,它将安装该服务,你可以忘记 InstallUtil.exe


Just tried to run an application via the following:

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...

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:

解决方案

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.

这篇关于如何解决“'installutil'不被识别为内部或外部命令,可操作的程序或批处理文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆