Question : add user to group

I have the following code to remove a user from a group.  How do you change this to add a user?  Will this work fine if I call this in a loop that might call it 10-20 times fast?

Private Shared Sub RemoveUserFromGroup(userDn As String, groupDn As String)
      Dim proc As Process = Process.Start("dsmod", String.Format("group ""{0}"" -rmmbr ""{1}""", groupDn, userDn))
      proc.WaitForExit()
      If proc.ExitCode <> 0 Then
            Console.WriteLine("Could not remove user {0} from group {1}", userDn, groupDn)
      End If
End Sub

Answer : add user to group

yes.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<DllImport("user32.dll")> _
Public Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function

Private Shared Sub AddUserToGroup(userDn As String, groupDn As String)
	Dim exitCode As Integer = StartBackgroundProcess("dsmod", String.Format("group ""{0}"" -addmbr ""{1}""", groupDn, userDn))
	If exitCode <> 0 Then
		Console.WriteLine("Could not remove user {0} from group {1}", userDn, groupDn)
	End If
End Sub

Private Shared Sub RemoveUserFromGroup(userDn As String, groupDn As String)
	Dim exitCode As Integer = StartBackgroundProcess("dsmod", String.Format("group ""{0}"" -rmmbr ""{1}""", groupDn, userDn))
	If exitCode <> 0 Then
		Console.WriteLine("Could not remove user {0} from group {1}", userDn, groupDn)
	End If
End Sub

Private Shared Function StartBackgroundProcess(procPath As String, cmdLine As String) As Integer
	Dim psi As New ProcessStartInfo(procPath, cmdLine)
	psi.WindowStyle = ProcessWindowStyle.Hidden
	psi.CreateNoWindow = True
	psi.UseShellExecute = False

	Dim proc As Process = Process.Start(psi)
	ShowWindow(proc.MainWindowHandle, 0)
	proc.WaitForExit()
	Return proc.ExitCode
End Function
Random Solutions  
 
programming4us programming4us