Add user to group - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

splay
Posts: 58
Joined: Tue May 15, 2007 6:09 pm

Add user to group

Hi Guys,

I am adding a user to a group.


Function add_user_to_group( user, group )

strComputer = get_computer_name()


Set objGroup = GetObject("WinNT://" & strComputer & "/" & group & ",group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & user & ",user")
show_error objUser.ADsPath
objGroup.Add( objUser.ADsPath )

End Function

This works perfect when I test the vbs from the command line, however when the installer is actually installing it throws an error.

I call the function add_user_to_group( "IUSR_MYCOMPUTER", "Administrators" )

From the command line, it works perfect but from the installer its a different story, I get an error saying the group "MyDomain/Everyone" doesnt exist, thing is I am not referencing the domain nor any groups on the domain, it seems the installer might be installing under my domain account that Im logged in under and is basically trying to add the user to the domain account.

Anyone know how I would specify that it is the local computer I want to add the user to?

Cheers

Splay
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Add user to group

Hi Splay,

Unfortunately the VBScript custom actions used by Windows Installer do not support parameters for the function you are calling. Instead, you can access the parameter values from installer properties. For example, in the install process you can use two custom properties: USER_NAME and GROUP_NAME. Also, for the custom action the "Function Name" field should be set to:

Code: Select all

add_user_to_group
In this case, the custom action would look like this:

Code: Select all

Function add_user_to_group()

  strComputer = get_computer_name()

  Dim group
  group = Session.Property("GROUP_NAME")
  Dim user
  user = Session.Property("USER_NAME")

  Set objGroup = GetObject("WinNT://" & strComputer & "/" & group & ",group")
  Set objUser = GetObject("WinNT://" & strComputer & "/" & user & ",user")
  show_error objUser.ADsPath
  objGroup.Add( objUser.ADsPath )

End Function
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
splay
Posts: 58
Joined: Tue May 15, 2007 6:09 pm

Re: Add user to group

Cosmin Hi,

Thats not the issue.

When executing the code from the comman line it does as it should "Add the user to the group ON MY LOCAL MACHINE"
When executing the code during the install it tries to "Add the user to the group ON THE DOMAIN CONTROLLER SERVER"

:)

Splay
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Add user to group

Hi Splay,

Since the computer name is retrieved through a custom function, perhaps the function doesn't work correctly. You can try showing the full command in a message box to see what computer name is used during the install.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
splay
Posts: 58
Joined: Tue May 15, 2007 6:09 pm

Re: Add user to group

Thanks Cosmin,

I think the thing is that when the msi is running, it runs under the domain account that the user is logged in as and hence it picks up the domain when creating the WinNT:// object.

When I run it under the command line it picks up the local computer and runs it no problems.

I could be wrong???
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Add user to group

Hi,

If the custom action runs without impersonation, perhaps it retrieves an incorrect computer name. In this case a solution would be to use the ComputerName property. If the custom action is Immediate you can access the property through the "Session" object:

Code: Select all

strComputer = Session.Property("ComputerName")
If the custom action is deferred you can pass the property through the Action Data field. In this case you can access the "CustomActionData" property inside the custom action:

Code: Select all

strComputer = Session.Property("CustomActionData")
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”