Adding a virtual service account to a group #8722
Replies: 3 comments 2 replies
-
Managed service accounts didn't exist when the User custom action was written, so scenarios using them are "new" (managed service accounts aren't that new but newer than the existing code 😄). Anyway, I'm pretty sure there was an issue opened about this scenario recently. It wouldd be interesting to have managed service accounts supported. |
Beta Was this translation helpful? Give feedback.
-
I think this might be a problem with timing. I think the CreateUser actions are occurring too early, before the Service itself has been configured (which is when the virtual service account exists). I think you might need to schedule the CreateUser deferred action to be AFTER the ServiceInstall. Other option you could try is, when the error is thrown. Try to do the group membership change that you're looking to do. I suspect it would fail because the user wouldn't yet exist... |
Beta Was this translation helpful? Give feedback.
-
I tried moving stuff around but no matter what I did, I could not get this to work. What I ended up doing is embedding that program above into the MSI and executing it as a type 2 deferred custom action scheduled after InstallServices. I still don't quite understand why that works and util doesn't. |
Beta Was this translation helpful? Give feedback.
-
(A quick note, I've had to scrub the names so ExampleService is replacing my actual service name.)
I am using Wix 4.0.5.
I have a service named ExampleService. This service is installed like this within a component:
In the same component, I have this:
In the package element, I have this:
Note that I've tried using
QueryWindowsWellKnownSIDs
which gives meBUILTIN\Administrators
which does not work with NetLocalGroupAddMembers.Anyways, when this executes, the service installs correctly. However, the install fails when it tries to add the user to a group. It provides a message box containing an OK button saying
Failed to add user to group. (-2147023509 NT SERVICE\ExampleService Administrators )
. I've had to manually type this out.Since the installer halts everything to provide this message box, I can look at the state of the install.
NT SERVICE\ExampleService
So... I looked into the code and logs. The related logs are as follows:
The error
0x8007056b
translates toERROR_NO_SUCH_MEMBER
meaning it doesn't think the user exists.I've tracked this down to this particular piece of code in the Util extension: https://github.com/wixtoolset/Util.wixext/blob/8a8a25695351ee542f08886a9d0957c78c6af366/src/ca/scaexec.cpp#L192
I cannot tell if the error is from NetGroupAddUser or NetLocalGroupAddMembers. In my case, I'm expecting NetLocalGroupAddMembers to be called. Regardless, to test if this works, I wrote this program that mimics what the Util extension does:
Since the installer prompts with that message box, I can run this to see if it works. Running it with
AddUserToGroup.exe "NT SERVICE\ExampleService" "Administrators"
provides the following output:This means that the program succeeded. The service account indeed is then part of the Administrator group. Sure enough, despite doing seemingly the same thing as the util extension, this works and the util extension failed.
I've tried a completely different approach as well, where instead of a virtual service account, I create a new user. Unfortunately, nobody should know the password to the service account (and ends up being a security risk potentially). I've tried generating a safe random password specifically for the installer but this doesn't appear to be possible. Even still, I've tried adding such a user to the Administrator group and it still fails with the util extension.
Anyways, I'm at my wits end with this. If anyone has any suggested alternatives, answers to the problems above, or insights, literally any help at this point would be appreciated. Really, all I want is a distinct user with some privileges to run a service. I would have figured this is an extremely common usecase but apparently, I'm either just missing the elephant or I'm doing something more unorthodox than I thought.
If a complete example with project files would help, I can create that as well.
Beta Was this translation helpful? Give feedback.
All reactions