【问题标题】:Using InstallUtil.exe and Setting Windows Service Password Containing Spaces使用 InstallUtil.exe 并设置包含空格的 Windows 服务密码
【发布时间】:2014-05-27 23:03:41
【问题描述】:

我们的安装应用程序会提示输入用户名和密码,并使用此信息安装 .NET 服务。我们有一个使用

安装的 Windows 服务
InstallUtil.exe
    /username=auser
    /password=password
    /name=TestService
    MyService.exe

在我们的客户开始使用包含空格的强密码之前,这一切正常。那么这就变成了:

InstallUtil.exe
    /username=auser
    /password=password
    with
    spaces
    /name=TestService
    MyService.exe

此调用失败并出现以下错误:

初始化安装时发生异常: System.IO.FileNotFoundException:无法加载文件或程序集 'file:///C:\Users\me[snip]\with' 或其依赖项之一。这 系统找不到指定的文件。

我们如何向 InstallUtil.exe 发送带空格的密码?

【问题讨论】:

    标签: c# .net service installutil


    【解决方案1】:

    您可以用双引号将每个参数括起来:

    installutil.exe "/username=user 1" "/password=pass word"
    

    【讨论】:

    • +1 我对此进行了测试,我很惊讶地发现它有效。我希望仅在数据部分周围需要引号,即/username="user 1"
    【解决方案2】:

    不带参数运行InstallUtil.exe,可以看到用法:

    用法:InstallUtil [/u | /卸载] [选项 [...]] 程序集 [[选项 [...]] 组装] [...]]

    在我提供的示例中,代码尝试发送密码“带空格的密码”。这被放置在命令行中,使安装程序认为密码是“password”并且程序集名称是“with”。不存在名为“with”的文件。这导致了System.IO.FileNotFoundException

    答案是在密码(以及 InstallUtil.exe 的任何其他参数)周围加上引号:

    InstallUtil.exe
        /username="user name with spaces"
        /password="password with spaces"
        /name="Service Name With Spaces"
        "Executable Name With Spaces.exe"
    

    【讨论】:

      猜你喜欢
      • 2010-09-13
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      相关资源
      最近更新 更多