chadmanvb
asked on
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
Private Shared Sub RemoveUserFromGroup(userDn
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
the sub name should be AddUserToGroup...
here it is:
Private Shared Sub AddUserToGroup(userDn As String, groupDn As String)
Dim proc As Process = Process.Start("dsmod", String.Format("group ""{0}"" -addmbr ""{1}""", groupDn, userDn))
proc.WaitForExit()
If proc.ExitCode <> 0 Then
Console.WriteLine("Could not add user {0} to group {1}", userDn, groupDn)
End If
End Sub
you can call it as many times as u want, just make sure to have the "proc.WaitForExit()" line in your loop.
ASKER
Ohhh, perfect. Is there anyway to supress the command window so the user does not see it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
ASKER
I'm not sure how to setup this up to run in the background. Mind looking at:
https://www.experts-exchange.com/questions/26420668/Run-cmd-in-background.html
https://www.experts-exchange.com/questions/26420668/Run-cmd-in-background.html
Private Shared Sub AddUserFromGroup(userDn As String, groupDn As String)
Dim proc As Process = Process.Start("dsmod", String.Format("group ""{0}"" -addmbr ""{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