Tuesday, October 28, 2008

More WiX stuff: Creating a user and adding them to a group.

Now that I am able to successfully create a new user I need to add that user to the Administrators group. Yeah, I hear you already, "That's a major security issue!" and I would tend to agree but this has been "mandated" by MercScum so there isn't much I can do about it.

Anyhoo. To do it I had do the following.

After the Product and Package element declarations I had to add a Group element, like this:



   1:  <Product Id="{F0C1692F-2D79-4D46-9BDF-DCBAD1DBCDDB}" Language="1033" Manufacturer="SomeManufacturer" Name="SomeProduct" UpgradeCode="{SOME-VALID-GUID}" Version="1.0.0.0">

   2:    <Package Compressed="yes" InstallerVersion="200" />

   3:      <util:Group Id="Administrators" Name="Administrators" />



It took some trial and error to find out where to put the util:Group element. The documentation says that it is a child of the Product element but I couldn't put it directly after. It had to go under the Package element. Good to know!

In my previously declared util:User element I had to nest a GroupRef element so the entire bit of XML reads like this:



   1:  <Component Id="RequiredUser" Guid="{SOME-VALID-GUID}">

   2:    <util:User Id="NewUser" Name="NewUserName" Password="supersekrit">

   3:      <util:GroupRef Id="Administrators"/>

   4:    </util:User>

   5:    <CreateFolder/>

   6:  </Component>



I was able to create the .msi and installed it on a VM and it worked like a charm. Luckily I only banged my head against the WiX brick wall for a few hours this time, unlike the create a new user head-banging. I suspect everything else will start to fall into place now that I am getting more comfortable with WiX and XML in general. Yes, I've managed to be in industry for almost 20 years without having to bow down to the great XML monster but now I am paying the price for being behind the curve. Back in my day we had CSVs and we liked 'em!

No comments: