If you're using local groups, you can do this by calling the system net
command. For example, to add a user to a group, you'd call:
net localgroup MyGroup /add SomeUser
Type net help localgroup
at a command prompt for more info.
You can also do this using WMI. This is VBScript but can be adapted to .NET or your preferred programming toolkit:
Dim oComputer
Computer = "computername"
Groupname = "Administrators"
ObjectToAdd = "Administrator"
' Bind to the computer.
Set oComputer = GetObject("WinNT://" & Computer & ",computer")
' get group object
Dim oGroup
Set oGroup = oComputer.GetObject("group", GroupName)
' Add the user object to the group.
oGroup.Add "WinNT://" & Computer & "/" & ObjectToAdd
Credit: Matt Hickman, http://www.tech-archive.net/Archive/WinXP/microsoft.public.windowsxp.wmi/2004-04/0007.html