0

我们的安装应用程序会提示输入用户名和密码,并使用此信息安装 .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 发送带空格的密码?

4

2 回答 2

3

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

installutil.exe "/username=user 1" "/password=pass word"
于 2014-05-27T23:11:54.477 回答
1

不带参数运行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"
于 2014-05-27T23:05:08.693 回答