Search code examples
xmlwixwindows-installer

Create a new user with an underscore in the name


I am trying to create a user in WiX, using the following XML:

  <Component Id="cmp_MyNewFolder" Guid="*">
    <util:User Id="MyNewUser"
      CreateUser="yes"
      Name="DUMMY&#95;USER"
      Domain="[ComputerName]"
      Password=""
      PasswordNeverExpires="yes"
      RemoveOnUninstall="yes"
      UpdateIfExists="yes" />
    <CreateFolder>
      <util:PermissionEx GenericAll="yes" User="DUMMY&#95;USER"/>
    </CreateFolder>
  </Component>

I've removed the GUID and password for this post, so the issue isn't with those. The problem is that whenever I run the .MSI, I get a generic error (Failed to create user) and the installation fails. After playing around with the XML a bit, I found out that giving the user a name that contains an underscore was causing the error. I have tried using the character literal and the XML entity for an underscore, but it is the same result either way.

What confuses me is that (based on what I've read) an underscore isn't considered to be a special character, and I have been able to create this user manually (with the underscore) without any problems. Is it possible to create a user with an underscore in the name, using WiX? Or will I have to settle for a different character?


Solution

  • It is allowed to use an underscore in the user's name. This code works and the installation package correctly creates the user.

    <Component Id="Component_User" Guid="{1B55F3FB-6B0F-4EF9-89ED-DB3ECA9106A4}">
        <util:User Id="MyNewUser"
                   CreateUser="yes"
                   Name="test_user"
                   Password="test"
                   PasswordNeverExpires="yes"
                   RemoveOnUninstall="yes"
                   UpdateIfExists="yes" />
        <CreateFolder>
            <util:PermissionEx GenericAll="yes" User="test_user"/>
        </CreateFolder>
    </Component>
    

    The verbose log might have more information about the error.