C# – Using InstallUtil.exe and Setting Windows Service Password Containing Spaces

cinstallutilnetservice

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?

Best Answer

You could enclose each parameter in double quotes:

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