Using InstallUtil.exe and Setting Windows Service Password Containing Spaces

5.7k Views Asked by At

Our install application prompts for a user name and password and installs a .NET service with this information. We have a Windows service that is installed using

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

This works fine until our customers start using strong passwords containing spaces. Then this becomes:

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

This call fails with the following error:

Exception occurred while initializing the installation: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Users\me[snip]\with' or one of its dependencies. The system cannot find the file specified.

How can we send a password with spaces to InstallUtil.exe?

2

There are 2 best solutions below

0
On BEST ANSWER

Running InstallUtil.exe with no parameters, you can see the usage:

Usage: InstallUtil [/u | /uninstall] [option [...]] assembly [[option [...]] assembly] [...]]

In the example I provided, the code tried to send the password "password with spaces". This was placed into the command line in a way that made the installer think the password is "password" and the assembly name is "with". No file named "with" existed. This caused the System.IO.FileNotFoundException.

The answer is to put quotes around the password (and any other parameters to InstallUtil.exe):

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

You could enclose each parameter in double quotes:

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