使用InstallUtil.exe并设置包含空格的Windows服务密码

时间:2014-05-27 23:03:42

标签: c# .net service installutil

我们的安装应用程序会提示输入用户名和密码,并使用此信息安装.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:无法加载文件或程序集   '文件:/// C:\用户\我[剪断] \与'或其中一个依赖项。该   系统找不到指定的文件。

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

2 个答案:

答案 0 :(得分:3)

您可以将每个参数括在双引号中:

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

答案 1 :(得分:1)

运行没有参数的InstallUtil.exe,您可以看到用法:

  

用法:InstallUtil [/ u | / uninstall] [option [...]] assembly [[option]   [...]]汇编] [...]]

在我提供的示例中,代码尝试发送密码“password with spaces”。这被放入命令行,使安装程序认为密码为“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"